我正在尝试将我的程序添加到注册表,这是我的代码
def regc():
reg = windll.kernel32
print(reg)
hkey = 'HKEY_CURRENT_USER'
lsubkey = 'Software\Microsoft\Windows\CurrentVersion\Run'
reserved = 0
flag = 'REG_OPTION_BACKUP_RESTORE'
samdesired = 'KEY_ALL_ACCESS'
ipsec = None
handle = reg.RegCreateKeyExA(hkey, lsubkey, reserved, flag, samdesired, ipsec, None)
它没有给我任何错误,但它仍然没有在注册表中创建新的项。我做错了什么
要正确使用}、
ctypes
,请定义.argtypes
和.restype
对参数进行错误检查。使用的许多类型都是错误的^例如,{flag
和samdesired
不是字符串。返回值不是句柄,而是状态。返回值是一个输出参数(pkhResult
在文档中)。您必须仔细阅读文档并检查所有变量定义的头文件另外,在Python 3中,字符串是Unicode的,因此使用Windows API的
W
形式来接受Unicode字符串。对子键使用原始字符串(r'...'
),因为它包含可以解释为转义码的反斜杠下面是一个工作示例:
输出:
处置值2表示密钥已存在(
REG_OPENED_EXISTING_KEY
)您还可以安装pywin32并在所有工作已经完成的地方使用
win32api.RegCreateKey
或win32api.RegCreateKeyEx
相关问题 更多 >
编程相关推荐