>>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

In your code sKeys is in fact not initialized prior to passing 
it as an argument to EnumKey method of objRegi class.  That is
why you are receiving traceback message.  Python doesn't know
what value to pass.

Hope info helps.
Regards,
Larry Bates
SysCon, Inc.



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
[EMAIL PROTECTED]
Sent: Saturday, August 17, 2002 2:02 PM
To: [EMAIL PROTECTED]
Subject: ActivePython digest, Vol 1 #417 - 1 msg


Send ActivePython mailing list submissions to
        [EMAIL PROTECTED]

To subscribe or unsubscribe via the World Wide Web, visit
        http://listserv.ActiveState.com/mailman/listinfo/activepython
or, via email, send a message with subject or body 'help' to
        [EMAIL PROTECTED]

You can reach the person managing the list at
        [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of ActivePython digest..."


Today's Topics:

   1. get registry with WMI in Python (Steven Nien)

--__--__--

Message: 1
From: Steven Nien <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: get registry with WMI in Python
Date: Sat, 17 Aug 2002 22:57:04 +0800

Hi

I 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


End of ActivePython Digest


_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython

Reply via email to