Search code examples
pythonwindowspython-3.xwmi

Python WMI _wmireg - retrieving values


I am trying to retrieve the values inside the Registry Object retrieved using python WMI.

import _winreg
import wmi
c = wmi.WMI(computer="10.31.247.8", user="devuser", password="devpass1!",namespace="root/default").StdRegProv


result, names = c.EnumKey (
hDefKey=_winreg.HKEY_LOCAL_MACHINE,
sSubKeyName="SYSTEM\ControlSet001\Services\MRxDAV"
)

for item in names:
    print item

Output:

EncryptedDirectories
Parameters
Security 
Enum

I want to retrieve the value of the string "ImagePath" present inside the directory HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\MRxDAV. The part I want to retrieve is provided in the image below:

enter image description here


Solution

  • You need to use the GetStringValue() method instead of EnumKey():

    import _winreg
    import wmi
    c = wmi.WMI(computer="10.31.247.8", user="devuser", password="devpass1!",namespace="root/default").StdRegProv
    
    result, imagePath = c.GetStringValue (
    hDefKey=_winreg.HKEY_LOCAL_MACHINE,
    sSubKeyName="SYSTEM\ControlSet001\Services\MRxDAV",
    sValueName="ImagePath"
    )
    print imagePath