Windows registry PermissionError
Mike Dewhirst
miked at dewhirst.com.au
Thu May 12 19:35:57 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 setup.
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
... on my very own laptop where my login has admistrator permissions ...
which I realise means nothing in this case.
But I would not have been surprised if it worked here but not in the
field where users are firefighters and definitely not administrators and
cannot install software on their workstations.
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 <<<<<
...
Any hints appreciated.
Cheers
Mike
--
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 --------------
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/python-list/attachments/20220513/2e3a964c/attachment.sig>
More information about the Python-list
mailing list