简体   繁体   中英

How can I change the DWORD value of a registry key via python?

I am trying to make a script that disables cmd. Here is my script:

import winreg
registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\Policies\Microsoft\Windows\System", 0, winreg.KEY_WRITE)
winreg.SetValueEx(registry_key, "DisableCMD", 0, winreg.REG_DWORD, "1")

But I get

Traceback (most recent call last):
  File "C:\Users\username\winregg.py", line 3, in <module>
    winreg.SetValueEx(registry_key, "DisableCMD", 0, winreg.REG_DWORD, "1")
ValueError: Could not convert the data to the specified type.

What am I doing wrong and how do I fix it?

Try this...

winreg.SetValueEx(registry_key, "DisableCMD", 0, winreg.REG_DWORD, 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM