Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在远程计算机上读取单个注册表项值_Python_Windows_Python 3.x_Winreg_Remote Registry - Fatal编程技术网

Python 在远程计算机上读取单个注册表项值

Python 在远程计算机上读取单个注册表项值,python,windows,python-3.x,winreg,remote-registry,Python,Windows,Python 3.x,Winreg,Remote Registry,我很难实现这个看似很简单的目标 我必须在多台机器上收集单个注册表项的值,以便审核扫描的机器是否需要使用更新版本的软件进行修补。根据我们公司的政策,我只能使用python 3(这是关于药物的,但我能做什么) 我一直在考虑使用winreg模块连接到远程机器(使用凭据,我们在一个域上),但我一次又一次地遇到 TypeError:对象不是PyHKEY对象 (或其他一些问题。) 这似乎是一个非常常见的需求,我一直很惊讶我在寻找python 3的示例时遇到的困难,我可以用这些示例来找出我做错了什么 如有任何

我很难实现这个看似很简单的目标

我必须在多台机器上收集单个注册表项的值,以便审核扫描的机器是否需要使用更新版本的软件进行修补。根据我们公司的政策,我只能使用python 3(这是关于药物的,但我能做什么)

我一直在考虑使用winreg模块连接到远程机器(使用凭据,我们在一个域上),但我一次又一次地遇到

TypeError:对象不是PyHKEY对象 (或其他一些问题。)

这似乎是一个非常常见的需求,我一直很惊讶我在寻找python 3的示例时遇到的困难,我可以用这些示例来找出我做错了什么


如有任何人愿意给予帮助,我们将不胜感激。提前谢谢。

你能展示一下你正在写的代码吗?你打开钥匙了吗?很多人因为没有打开它而遇到问题?这只是一个猜测,希望能奏效

key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Enum\Root')

winreg
模块不允许您执行
reg查询所做的操作。例如,要读取
BuildLabEx
reg键值,我要做的是:

import subprocess

keyPath = "\\\\RemoteMachineName\\HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion"
output = subprocess.run(["reg", 
                 "query",
                 keyPath,
                 "/v",
                 "BuildLabEx"], 
               capture_output=True,
               text=True)
print(output.stdout)
上述代码段相当于:

reg query "\\RemoteMachineName\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx

你能提供你正在使用的代码吗?你必须先打开钥匙,即使你想删除它。错误消息来自使用无效(即打开的)密钥句柄的对象调用winreg方法。