For some reason Chrome isn't updating in our environment and I found a solution that changes the value of a reg key. I'm trying to create a script that makes this change on all systems in our environment. The script should first check to see if it exists, and if it does change the value to 1. If it doesn't, it would note that in a text file in a preexisting location. This is what I have so far.
import winreg
import socket
Update_Path = "SOFTWARE\\Policies\\Google\\Update"
Key = "Update{8A69D345-D564-463C-AFF1-A69D9E530F96}"
No_Reg_PC = socket.gethostname()
try:
winreg.SetValueEx(Key, "Enable Chrome Updates", 0, winreg.REG_DWORD, 0)
except FileNotFoundError:
with open('\\*\\*\\Scripts\\Logs\\ChromeUpdates.txt', 'w') as f:
f.write(f'{No_Reg_PC} didn\'t have the appropriate reg keys and couldn\'t enable Chrome updates')
f.close()
Whenever I run it I get the following error
Traceback (most recent call last):
File "u:\RandoScripts\ChromeUpdatesv2.py", line 9, in <module>
winreg.SetValueEx(Key, "Enable Chrome Updates", 0, winreg.REG_DWORD, 0)
TypeError: The object is not a PyHKEY object
I've included an image of the reg key I'm trying to change below for added contexts. REG KEY
I tried changing the formatting of the \ as that was a popular response.
You are passing the
string"Update{8A69D345-D564-463C-AFF1-A69D9E530F96}" as a key, hence the error you are seeing.As you are wishing to work with remote computers, you'll want to look at the ConnectRegistry method. e.g.
HKEY_LOCAL_MACHINE is a constant defined by winreg.
You should then be able to use:
(I've also changed your last zero integer argument to a string, as the documentation says it should be.)
As a side-note: it is advisable to use all lower case for Python variables in your code. (Apart from constants which should be all upper.)