Page 1 of 1

[SOLVED] Creating a package to modify the Windows registry

Published: February 20, 2020 - 10:59 AM
by Minus
Good morning

I would like to use Wapt to deploy a modification to a key in the Windows registry related to Outlook settings on certain PCs

My basic .reg file looks like this:

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\AutoDiscover]
"ExcludeExplicitO365Endpoint"=dword:00000001
So I created two batch files as follows:

The first one is to install the key (AntiPopup.bat):

Code: Select all

@echo off
REG ADD HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /f /v ExcludeExplicitO365Endpoint /t REG_DWORD /d "00000001"
The second one is to remove the key (RemoveAntiPopup.bat)

Code: Select all

@echo off
REG DELETE HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v ExcludeExplicitO365Endpoint /f
Initially, I tested the batch files in a VM, and they worked without any problems

However, once the WAPT package is created with the following setup.py:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def install():
    print('AntiPopup.bat: Execute...')
    run(r'AntiPopup.bat')

def uninstall():
    print('RemoveAntiPopup.bat: Execute...')
    run(r'RemoveAntiPopup.bat')
The installation proceeds without error, but the key is not created in the VM.

Thinking there might be a problem with the application of a batch file, I converted the batch files into exe files with admin rights.

I tested the executable files directly in the VM; they create and delete the key correctly

I created the setup.py file as follows:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def install():
    print('AntiPopup.exe: Execute...')
    run(r'AntiPopup.exe')

def uninstall():
    print('RemoveAntiPopup.exe: Execute...')
    run(r'RemoveAntiPopup.exe')
And there, the same problem as before: the package runs fine without error, but the .exe file doesn't apply, as if it weren't running

Can you help me please? I have quite a few small packages like this to create.

Thank you in advance

### Required Information###
Server running Debian 9
Windows 10 Pro Admin Machine (1909)
WAPT Server version: 1.8.1
WAPT Agent version: 1.8.1.6740
WAPT Setup version: 1.8.1.6740
WAPT Deploy version: 1.8.1.6740
Database status: OK (1.7.6.6)

Re: Creating a package to modify the Windows registry

Published: February 20, 2020 - 1:46 PM
by agauvrit
Hello,

It's simpler with the right function: https://www.wapt.fr/fr/doc/wapt-create- ... gistry-key

Alexandre

Re: Creating a package to modify the Windows registry

Published: February 20, 2020 - 2:02 PM
by Minus
As a beginner learning Python, is this type of simple setup.py file suitable?

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
 
registry_setstring(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Office\\16.0\\Outlook\\Autodiscover",'ExcludeExplicitO365Endpoint','00000001', type=REG_DWORD)

Re: Creating a package to modify the Windows registry

Published: February 20, 2020 - 2:11 PM
by agauvrit
So I just got a reprimand from my colleague; it's an HKCU key, so it can't be modified in the system context, only in the user context! (Thanks, Simon)

The correct answer is:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def install():
    pass

def uninstall():
    pass
    
def session_setup():
    registry_setstring(HKEY_CURRENT_USER, r"SOFTWARE\Microsoft\Office\16.0\Outlook\Autodiscover",'ExcludeExplicitO365Endpoint',1, type=REG_DWORD)
To understand how session_setup() works: https://www.wapt.fr/fr/doc/wapt-create- ... nvironment

First, you need to install the package > then run the command

Code: Select all

wapt-get session-setup ALL
on the workstation to execute the session_setup function

Alexander

Re: Creating a package to modify the Windows registry

Published: February 20, 2020 - 2:17 PM
by Minus
Thank you very much for the information, and sorry for causing a reprimand. :?

Okay for the `wapt-get session-setup ALL` command; it's easy to run via a GPO.

So, if it were an HKLM key? What should the setup.py file look like?

Re: Creating a package to modify the Windows registry

Published: February 20, 2020 - 5:47 PM
by agauvrit
For HKLM > system context

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def install():
    registry_setstring(HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Office\16.0\Outlook\Autodiscover",'ExcludeExplicitO365Endpoint',1, type=REG_DWORD)
    

Re: Creating a package to modify the Windows registry

Published: February 21, 2020 - 09:17
by Minus
Great!

Thank you so much for all this information.