Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
[Consumer]
consumer = 
consumer site = 
consumer application = 

[LOCAL INSTALL]
entry point = 
working directory = C:\Users\
install directory = C:\Users\
plugin directory = C:\Users\

[GUI SETTINGS]
part_setting1 = blue
color_settings_1 = blue
color_settings_2 = pink

[DEFAULT SETTINGS]
crosshair_color =


Python
import os
import sys
import configparser
import winreg


config_plugin = configparser.ConfigParser()
config_plugin.read(path)
plugin_dir = config_plugin

REG_PATH = plugin_dir

reg_connection = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)

reg_key = winreg.OpenKey(reg_connection, path)

winreg.CreateKey(reg_key, "New Key")

    for key in range(3000):
        try:
           show_sub_keys = winreg.EnumKey(reg_key, key)
           print(show_sub_keys)
    except WindosError:
        break

new_key_value = winreg.OpenKey(reg_connection,  path)
winreg.SetValueEx(new_key_value, "New Value",0,winreg.REG_SZ, "This Value")
winreg.CloseKey(new_key_value)


What I have tried:

Im trying to add this ini dynamically in windows registry using a python code but have never done this, i created this ini file in my `python project and keep getting an error of not finding the path
Posted
Updated 9-Mar-23 8:16am
v2
Comments
Richard MacCutchan 9-Mar-23 10:10am    
Exactly which line produces the error, and what is the complete text of the message.

1 solution

Basically, don't - it'll only cause you grief.
When the registry was first created, it was pretty much public, anyone could stick anything in it. And so they did - it got bloated, slow, and unreliable so access became restricted, and each successive version of the OS added restrictions. It seems that this trend towards a totally secure registry will continue.

Instead, there are folders in Windows that are specifically there to hold user data such as INI files (though XML / JSON is generally considered a better idea these days): Special folder - Wikipedia[^]
You can get the path to these at run time either via win32com.SHGetFolderPath:
Python
from win32com.shell import shell, shellcon
print shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
or by using a python wrapper like userpaths · PyPI[^] (Google can find you several different such wrappers).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900