Page 1 of 1

[SOLVED] registry_set not working?

Published: June 5, 2019 - 11:39
by renaud.counhaye
Hello everyone,

Currently on servers
WAPT Server version: 1.7.4
WAPT Agent version: 1.7.4.6077
WAPT Setup version: 1.7.4.6077
WAPT Deploy version: 1.7.4.6077
Database status: OK (1.7.4.0)

I have this new script to block automatic Windows 10 restarts with Windows Update

Code: Select all

from setuphelpers import *
#list de paquets à oublier tout simplement.

uninstallkey = []

#def main():
def install():
    if(windows_version() >= Version('10.0')):
        print('is windows 10')
        #reg
        registry_set('HKEY_LOCAL_MACHINE',r'SOFTWARE/Policies/Microsoft/Windows/WindowsUpdate/AU','NoAutoRebootWithLoggedOnUsers',1,type=REG_DWORD)
        # registry_set(HKEY_LOCAL_MACHINE, r'SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System','MaxGPOScriptWait',180,type=REG_DWORD)
        print('key set. reboot required to be taken in count.')
    else:
        print('not w10')

if __name__ == '__main__': #run debug
    install()

def uninstall():
    if(reg_key_exists('HKEY_LOCAL_MACHINE',r'SOFTWARE/Policies/Microsoft/Windows/WindowsUpdate/AU','NoAutoRebootWithLoggedOnUsers')):
        registry_set('HKEY_LOCAL_MACHINE',r'SOFTWARE/Policies/Microsoft/Windows/WindowsUpdate/AU','NoAutoRebootWithLoggedOnUsers',0,type=REG_DWORD)
I've tried changing the path using backslashes (\\) and removing the 'r' in front (which, by the way, I don't understand the purpose of), but I still get this error when trying to run it locally via Pyscripter:
*** Remote Interpreter Reinitialized ***
is windows 10
Traceback (most recent call last):
File "C:\waptdev\ymg-WU10-autorebootblock-wapt\setup.py", line 23, in
install()
File "C:\waptdev\ymg-WU10-autorebootblock-wapt\setup.py", line 17, in install
registry_set('HKEY_LOCAL_MACHINE',r'SOFTWARE/Policies/Microsoft/Windows/WindowsUpdate/AU','NoAutoRebootWithLoggedOnUsers',1,type=REG_DWORD)
File "C:\Program Files (x86)\wapt\setuphelpers.py", line 1654, in registry_set
with reg_openkey_noredir(root,path,sam=KEY_WRITE,create_if_missing=True) as key:
File "C:\Program Files (x86)\wapt\setuphelpers.py", line 1431, in reg_openkey_noredir
result = _winreg.OpenKey(rootkey,subkeypath,0, sam | _winreg.KEY_WOW64_64KEY)
TypeError: The object is not a PyHKEY object


And I get a similar error if I try to deploy it via the console afterwards:
is windows 10Traceback (most recent call last):
File "C:\Program Files (x86)\wapt\common.py", line 3818, in install_wapt
exitstatus = setup.install()
File "c:\users\rcu\appdata\local\temp\waptx2yigf\setup.py", line 17, in install
File "C:\Program Files (x86)\wapt\setuphelpers.py", line 1654, in registry_set
with reg_openkey_noredir(root,path,sam=KEY_WRITE,create_if_missing=True) as key:
File "C:\Program Files (x86)\wapt\setuphelpers.py", line 1431, in reg_openkey_noredir
result = _winreg.OpenKey(rootkey,subkeypath,0, sat | _winreg.KEY_WOW64_64KEY)
TypeError: The object is not a PyHKEY object
TypeError: The object is not a PyHKEY object
Could this be a permissions error?

Thank you, best regards,
Renaud.

Re: registry_set not working? [SOLVED]

Published: June 5, 2019 - 2:47 PM
by renaud.counhaye
I was able to fix my problem with this line:
registry_set(HKEY_LOCAL_MACHINE,makepath('SOFTWARE','Policies','Microsoft','Windows','WindowsUpdate','AU'),'NoAutoRebootWithLoggedOnUsers',1,type=REG_DWORD)

Re: registry_set not working? [SOLVED]

Published: June 5, 2019 - 3:09 PM
by Patrice_minagri
Good morning,

I would have written the registry_set as follows:

Code: Select all

registry_set(HEY_LOCAL_MACHINE, "Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU, 'NoAutorebootWithLoggedOnUsers', 1, type=REG_DWORD)
instead of :

Code: Select all

registry_set('HKEY_LOCAL_MACHINE',r'SOFTWARE/Policies/Microsoft/Windows/WindowsUpdate/AU','NoAutoRebootWithLoggedOnUsers',1,type=REG_DWORD)
Although the value 1 must take the form of 0x01 in the instruction for data of type REG_DWORD (I don't remember offhand).

This works with \\

Sincerely.

Patrice

Re: registry_set not working? [SOLVED]

Published: June 5, 2019 - 4:36 PM
by renaud.counhaye
Hi Patrice, :)

as I said earlier, I did try the path with backslashes, but it didn't work for me. :/
Maybe just luck?

Cheers