Python Forum
How to add new registry key - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to add new registry key (/thread-12149.html)



How to add new registry key - shlomi27 - Aug-11-2018

I need to add new registry
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
how to make it with python
Thanks,


RE: How to add new registry key - metulburr - Aug-11-2018

Try this
https://github.com/metulburr/random/blob/master/registry_keys.py

Winreg docs
https://docs.python.org/3.6/library/winreg.html


RE: How to add new registry key - shlomi27 - Aug-15-2018

After checking the link I got from Metulburr I came up to following code but still failed on

ValueError: Could not convert the data to the specified type.

import winreg as wreg

def newregkey():
    key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\system")
    wreg.SetValue(key, 'NewSubkey', wreg.REG_SZ, 'LocalAccountTokenFilterPolicy')
    wreg.SetValueEx(key, 'ValueName', 0, wreg.REG_DWORD, '0x00000001')
    key.Close()
can any one tell me what is wrong

Traceback:
File "C:\Program Files\Python36\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:\page\Backup\LandaUtilitiesInstallar.py", line 407, in <lambda>
self.InstallButtom.bind('<Button-1>',lambda e:LandaUtilitiesInstallar_support.install_lclick(e))
File "C:\page\Backup\LandaUtilitiesInstallar_support.py", line 113, in install_lclick
newregkey()
File "C:\page\Backup\LandaUtilitiesInstallar_support.py", line 70, in newregkey
wreg.SetValueEx(key, 'ValueName', 0, wreg.REG_DWORD, '0x00000001')
ValueError: Could not convert the data to the specified type.


RE: How to add new registry key - reidnax - Feb-04-2021

wreg.SetValueEx(key, 'ValueName', 0, wreg.REG_DWORD, 1)
You are giving input as a string it takes hexadecimal or a decimal as an input