Python WMI _wmireg - 检索值

发布于 2024-12-06 03:09:52 字数 617 浏览 0 评论 0原文

我正在尝试检索使用 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

输出:

EncryptedDirectories
Parameters
Security 
Enum

我想检索目录 HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\MRxDAV 中存在的字符串“ImagePath”的值。我想要检索的部分如下图所示:

在此处输入图像描述

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把回忆走一遍 2024-12-13 03:09:52

您需要使用 GetStringValue() 方法而不是 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

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
木槿暧夏七纪年 2024-12-13 03:09:52
def get_reg(self):
    # https://msdn.microsoft.com/en-us/library/windows/desktop/aa384911(v=vs.85).aspx
    HKEY_CLASSES_ROOT = 2147483648
    HKEY_CURRENT_USER = 2147483649
    HKEY_LOCAL_MACHINE = 2147483650
    HKEY_USERS = 2147483651
    HKEY_CURRENT_CONFIG = 2147483653

    KEY_QUERY_VALUE = 1  # Required to query the values of a registry key.
    KEY_SET_VALUE = 2 # Required to create, delete, or set a registry value.
    KEY_DEFAULT_VALUE = 3  # KEY_QUERY_VALUE | KEY_SET_VALUE Default value, allows querying, creating, deleting, or setting a registry value.
    KEY_CREATE_SUB_KEY = 4 # Required to create a subkey of a registry key.
    KEY_ENUMERATE_SUB_KEYS = 8 # Required to enumerate the subkeys of a registry key.
    KEY_NOTIFY = 16 # Required to request change notifications for a registry key or for subkeys of a registry key.
    KEY_CREATE = 32 # Required to create a registry key.
    DELETE = 65536 # Required to delete a registry key.
    READ_CONTROL = 131072 # Combines the STANDARD_RIGHTS_READ, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY values.
    WRITE_DAC = 262144 # Required to modify the DACL in the object's security descriptor.
    WRITE_OWNER = 524288 # Required to change the owner in the object's security descriptor.

    #c = wmi.WMI(computer="XXX.XXX.XXX.XXX", user="devuser",password="devpass1!",namespace="root/default").StdRegProv
    c = wmi.WMI(find_classes=False,namespace="default",computer=self.computer).StdRegProv

    print "Methods: "
    print str(c)

    try:
        subkey = r"SYSTEM\CurrentControlSet\Services\LanmanWorkstations"
        name = "EnablePlainTextPassword"

        result, grants = c.CheckAccess(hDefKey = HKEY_LOCAL_MACHINE, sSubKeyName=subkey, uRequired=KEY_DEFAULT_VALUE);

        print "Access : " + str(grants)

        #result, value = c.GetStringValue(hDefKey=_winreg.HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=name)
        #print "HKEY_LOCAL_MACHINE " + str(HKEY_LOCAL_MACHINE)
        #err, sids = c.EnumKey (hDefKey=2147483650, sSubKeyName=subkey)
        #for sid in sids:
        #  print sid

        # https://msdn.microsoft.com/en-us/library/windows/desktop/aa390461(v=vs.85).aspx
        name = "OtherDomains"
        subkey = r"SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters"
        err, names, types = c.EnumValues (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey)

        for i in range(len(names)):
            if types[i] == REG_SZ:
                tipo = "Data Type: String"
                result, value = c.GetStringValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
            elif types[i] == REG_EXPAND_SZ:
                tipo = "Data Type: Expanded String"
                result, value = c.GetExpandedStringValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
            elif types[i] == REG_BINARY:
                tipo = "Data Type: Binary"
                result, value = c.GetBinaryValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
            elif types[i] == REG_DWORD:
                tipo = "Data Type: DWORD"
                # 32 Bits
                result, value = c.GetDWORDValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
                # 64 Bits
                #result, value = c.GetQWORDValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
            elif types[i] == REG_MULTI_SZ:
                tipo = "Data Type: Multi String"
                result, value = c.GetMultiStringValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])

            print names[i] + " = " + tipo + " " + str(value)

    except Exception as e:
        print "Erro: ", str(e)
def get_reg(self):
    # https://msdn.microsoft.com/en-us/library/windows/desktop/aa384911(v=vs.85).aspx
    HKEY_CLASSES_ROOT = 2147483648
    HKEY_CURRENT_USER = 2147483649
    HKEY_LOCAL_MACHINE = 2147483650
    HKEY_USERS = 2147483651
    HKEY_CURRENT_CONFIG = 2147483653

    KEY_QUERY_VALUE = 1  # Required to query the values of a registry key.
    KEY_SET_VALUE = 2 # Required to create, delete, or set a registry value.
    KEY_DEFAULT_VALUE = 3  # KEY_QUERY_VALUE | KEY_SET_VALUE Default value, allows querying, creating, deleting, or setting a registry value.
    KEY_CREATE_SUB_KEY = 4 # Required to create a subkey of a registry key.
    KEY_ENUMERATE_SUB_KEYS = 8 # Required to enumerate the subkeys of a registry key.
    KEY_NOTIFY = 16 # Required to request change notifications for a registry key or for subkeys of a registry key.
    KEY_CREATE = 32 # Required to create a registry key.
    DELETE = 65536 # Required to delete a registry key.
    READ_CONTROL = 131072 # Combines the STANDARD_RIGHTS_READ, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY values.
    WRITE_DAC = 262144 # Required to modify the DACL in the object's security descriptor.
    WRITE_OWNER = 524288 # Required to change the owner in the object's security descriptor.

    #c = wmi.WMI(computer="XXX.XXX.XXX.XXX", user="devuser",password="devpass1!",namespace="root/default").StdRegProv
    c = wmi.WMI(find_classes=False,namespace="default",computer=self.computer).StdRegProv

    print "Methods: "
    print str(c)

    try:
        subkey = r"SYSTEM\CurrentControlSet\Services\LanmanWorkstations"
        name = "EnablePlainTextPassword"

        result, grants = c.CheckAccess(hDefKey = HKEY_LOCAL_MACHINE, sSubKeyName=subkey, uRequired=KEY_DEFAULT_VALUE);

        print "Access : " + str(grants)

        #result, value = c.GetStringValue(hDefKey=_winreg.HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=name)
        #print "HKEY_LOCAL_MACHINE " + str(HKEY_LOCAL_MACHINE)
        #err, sids = c.EnumKey (hDefKey=2147483650, sSubKeyName=subkey)
        #for sid in sids:
        #  print sid

        # https://msdn.microsoft.com/en-us/library/windows/desktop/aa390461(v=vs.85).aspx
        name = "OtherDomains"
        subkey = r"SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters"
        err, names, types = c.EnumValues (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey)

        for i in range(len(names)):
            if types[i] == REG_SZ:
                tipo = "Data Type: String"
                result, value = c.GetStringValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
            elif types[i] == REG_EXPAND_SZ:
                tipo = "Data Type: Expanded String"
                result, value = c.GetExpandedStringValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
            elif types[i] == REG_BINARY:
                tipo = "Data Type: Binary"
                result, value = c.GetBinaryValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
            elif types[i] == REG_DWORD:
                tipo = "Data Type: DWORD"
                # 32 Bits
                result, value = c.GetDWORDValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
                # 64 Bits
                #result, value = c.GetQWORDValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])
            elif types[i] == REG_MULTI_SZ:
                tipo = "Data Type: Multi String"
                result, value = c.GetMultiStringValue(hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=subkey, sValueName=names[i])

            print names[i] + " = " + tipo + " " + str(value)

    except Exception as e:
        print "Erro: ", str(e)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文