using variables with modules

runes rune.strand at gmail.com
Thu May 5 06:44:16 EDT 2005


I tested your code and made a few changes:

import _winreg
import sys

readfile = open("C:\scripts\ip.txt", 'r')
IPList = readfile.readlines()

for ClientIP in IPList:
    ClientIP = ClientIP.strip()
    ClientIP = r'\\' +  ClientIP
    try:
    	key = _winreg.ConnectRegistry(ClientIP,
_winreg.HKEY_LOCAL_MACHINE)
    except EnvironmentError:
    	sys.exit("EnvironmentError occured")
    hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
                           "SOFTWARE\Microsoft\Windows
NT\CurrentVersion")
    OSver=_winreg.QueryValueEx( hkey, "ProductName")
    print OSver

print "Exiting Script"
sys.exit()

It gives the following output on my XP box when running it against a
ip.txt with two IP's, the firste being the box it self, the second a
non-domain 2003-server in the network:

(u'Microsoft Windows XP', 1)
EnvironmentError occured




More information about the Python-list mailing list