Here's a lower level way of doing it in python.
---------
from win32api import *
from win32con import *
root = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 0, KEY_READ)
try:
keys = []
ok = 1
i = 0
while ok:
try:
keys.append(RegEnumKey(root, i))
except:
ok = 0
i += 1
finally:
RegCloseKey(root)
print keys
---------
What's happening in your code is, the COM function is expecting an array passed by reference that it can fill with the data. Python normally deals with such calls by returning the array like it was part of the function, so you code would be something like:
iRC, sKeys = objRegi.EnumKey(HKLM, sBaseKey)But I think you need to run the COM makePy Utility found in the tools menu of the ActiveState win IDE on the COM object before you can do that. Unfortunately I don't know how if or under what name that COM object is registered, so I couldn't do it.
In the activestate help look up win32api in the index. And search for python examples on the net rather than VB examples which can be hard to translate. There are plenty around.
GBU
Matthew Sherborne
Steven Nien wrote:
HiI find some scripts in Microsoft MSDN. For example: HostName="localhost" Dim oRegistry, sBaseKey, iRC, sKey, arSubKeys, sValue Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE On Error Resume Next Set oRegistry = _ GetObject("winmgmts:{ImpersonationLevel=Impersonate}//" & _ HostName & "/root/default:StdRegProv") If Err <> 0 Then wscript.echo "Line 9, " & Err.Number & ", " & _ Err.Description Err.Clear wscript.quit End if sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys) If Err <> 0 Then wscript.echo "Line 23, " & Err.Number & ", " & _ Err.Description Err.Clear wscript.quit End if For Each sKey In arSubKeys iRC = oRegistry.GetStringValue(HKLM, sBaseKey & sKey, _ "DisplayName",sValue) If Err <> 0 Then wscript.echo "Line 32, " & Err.Number & ", " & _ Err.Description Err.Clear wscript.quit End if If iRC <> 0 Then oRegistry.GetStringValue HKLM, sBaseKey & _ sKey, "QuietDisplayName", sValue If Err <> 0 Then wscript.echo "Line 42, " & Err.Number & ", " & _ Err.Description Err.Clear wscript.quit End if End If If sValue <> "" Then wscript.echo sValue End If Next After run the script, I can get Uninstall software list in registry. I try to do it with Python. The code is: from win32com.client import GetObject HKLM = 0x80000002L objRegi = GetObject("winmgmts://./root/default:StdRegProv") sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" iRC = objRegi.EnumKey(HKLM, sBaseKey, sKeys) for sKey in arSubKeys: print sKey After run the code, I get some error message: Traceback (most recent call last): File "D:\steven\itim\t2.py", line 6, in ? iRC = objRegi.EnumKey(HKLM, sBaseKey, sKeys) NameError: name 'sKeys' is not defined I don't know why. Could someone give me a hint? Thanks very much. -- Steven Nien _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython