Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add new registry key
#1
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,
Reply
#2
Try this
https://github.com/metulburr/random/blob...ry_keys.py

Winreg docs
https://docs.python.org/3.6/library/winreg.html
Recommended Tutorials:
Reply
#3
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.
Reply
#4
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
nilamo likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to add Python folder in Windows Registry ? Touktouk 1 206 Feb-20-2024, 01:04 PM
Last Post: DeaD_EyE
  Read complete windows registry? fredep57 3 901 Mar-15-2023, 08:14 PM
Last Post: buran
  Automatic registering python to registry kozaizsvemira 1 2,142 Oct-22-2019, 11:23 AM
Last Post: kozaizsvemira
  How to ignore - ERROR: The system was unable to find the specified registry key or va asheru93 9 6,547 Feb-04-2019, 06:35 AM
Last Post: asheru93
  Registry Key Access malonn 11 9,114 Jul-26-2018, 09:45 AM
Last Post: gontajones
  Looking for advice about "registry" implementation voltron 0 2,269 Feb-06-2018, 07:26 AM
Last Post: voltron
  Python 3.x Windows 7 registry file associations broken pixhellmann 2 5,007 Sep-12-2017, 09:14 PM
Last Post: Larz60+
  [WinReg]>Issue when reading a registry key CSA75 4 8,832 Mar-28-2017, 03:35 PM
Last Post: CSA75

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020