I'm trying to copy a value from HKLM to HKCU for application rollout via bulk installation by an administrator but individual Windows user authentication. The installer can write to HKLM but the user needs to see the value in HKCU

Any hints appreciated.

Thanks

Mike

Getting this ...

Traceback (most recent call last):
  File "D:\Users\mike\envs\chemdata\registry\wreg\wreg.py", line 84, in <module>
    curegistry.setvalue('Country', anz)
  File "D:\Users\mike\envs\chemdata\registry\wreg\wreg.py", line 51, in setvalue
    return wr.SetValueEx(self.select(), vname, 0, 1, value)
PermissionError: [WinError 5] Access is denied

from ...

import winreg as wr


class Registry:

    def __init__(self, computer=None, hkey=None, sub_key=None):
        # computer is None means this computer
        self.computer = computer
        self.key = hkey
        self.sub_key = sub_key

    def connect(self):
        return wr.ConnectRegistry(self.computer, self.key)

    def select(self):
        # also tried OpenKeyEx()
        return wr.OpenKey(
            key=self.key,
            sub_key=self.sub_key,
            access=wr.KEY_ALL_ACCESS + wr.KEY_WRITE,
        )

    def query(self, vname):
        return wr.QueryValueEx(self.select(), vname)

    def setvalue(self, vname, value):
        return wr.SetValueEx(self.select(), vname, 0, 1, value)

if __name__ == "__main__":

    lmregistry = Registry(
        hkey=wr.HKEY_LOCAL_MACHINE,
        sub_key="SOFTWARE\WOW6432Node\XXX Technology\AppName",
    )
    print(f"\n{lmregistry.sub_key}")
    anz = lmregistry.query('Country')[0]
    print(f"\n{anz}") # works fine

    curegistry = Registry(
        hkey=wr.HKEY_CURRENT_USER,
        sub_key="SOFTWARE\XXX Technology\AppName",
    )
    curegistry.setvalue('Country', anz)  <<<<< BOOM <<<<<
    anz = curegistry.query('Country')[0]



--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
melbourne-pug mailing list
melbourne-pug@python.org
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to