[SOLVED] registry_set not working?

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
renaud.counhaye
Messages: 31
Registration: December 13, 2017 - 11:45

June 5, 2019 - 11:39

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.
Last edited by renaud.counhaye on June 5, 2019 - 2:48 PM, edited 1 time.
Renaud Counhaye,
Network Systems Technician,
Central Functions Division
, Ymagis Group
Picture
renaud.counhaye
Messages: 31
Registration: December 13, 2017 - 11:45

June 5, 2019 - 2:47 PM

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)
Renaud Counhaye,
Network Systems Technician,
Central Functions Division
, Ymagis Group
Picture
Patrice_minagri
Messages: 57
Registration: Oct 21, 2016 - 4:56 p.m.

June 5, 2019 - 3:09 PM

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
WAPT 1.7.4
renaud.counhaye
Messages: 31
Registration: December 13, 2017 - 11:45

June 5, 2019 - 4:36 PM

Hi Patrice, :)

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

Cheers
Renaud Counhaye,
Network Systems Technician,
Central Functions Division
, Ymagis Group
Picture
Locked