using variables with modules

marc.wyburn at gb.unisys.com marc.wyburn at gb.unisys.com
Thu May 5 05:36:49 EDT 2005


Hi, I am trying to move away from Windows only scripting to Python.
I've written a quick script that will pull the product version from the
client registry.  I can get the IP addresses from a file into a list
and then pull each element in the list using the for loop.  I am
setting each element to a varuable ClientIP.  When I try to use that
variable in _winreg values it is not substituting the element from the
list.  If I type the list value straight into the _winreg command it
works fine. The IPaddresses in the list are surrounded by quotes.  So

1. can I use variables with modules? (I have assumed that I can!)
2. does putting quotes around the IPaddress in the list create a
problem (my list is something like ["192.168.0.1","192.168.0.2"]

I've also tried not having the list elements in quotes and using %s
substitution in the _winreg command.

Any help would be much appreciated, Cheers, MW.

#Query ProductName in windows Registry

import _winreg
import sys

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

for ClientIP in IPList:
	print ClientIP
	key = _winreg.ConnectRegistry(ClientIP, _winreg.HKEY_LOCAL_MACHINE)
	hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
"SOFTWARE\Microsoft\Windows NT\CurrentVersion")
	OSver=_winreg.QueryValueEx( hkey, "ProductName")
	print OSver

print "Exiting Script"
sys.exit()




More information about the Python-list mailing list