[melbourne-pug] Windows registry PermissionError
Mike Dewhirst
miked at dewhirst.com.au
Thu May 12 19:24:28 EDT 2022
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/melbourne-pug/attachments/20220513/7a8524e3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <https://mail.python.org/pipermail/melbourne-pug/attachments/20220513/7a8524e3/attachment.sig>
More information about the melbourne-pug
mailing list