Attention : support for WAPT 1.8.2 ended on June the 30th 2022.

There are known vulnerabilities in WAPT dependencies in WAPT 1.8.2 branch. Please upgrade to the latest supported version. CVE listing (non exhaustive) :
  • * python engine : python 2.7 (CVE-2020-10735, CVE-2015-20107, CVE-2022-0391, CVE-2021-23336, CVE-2021-3177, CVE-2020-27619, CVE-2020-26116, CVE-2019-20907, CVE-2020-8492, etc.)
  • * cryptography : openssl : CVE-2022-2068, CVE-2022-1292, CVE-2022-0778, CVE-2021-4160, CVE-2021-3712, CVE-2021-23841, CVE-2021-23840, CVE-2021-23839, CVE-2020-1971, CVE-2020-1968, CVE-2019-1551
  • * python dependencies : cryptography (CVE-2020-36242, CVE-2020-25659), eventlet (CVE-2021-21419), jinja2 (CVE-2020-28493), psutil (CVE-2019-18874), waitress (CVE-2022-31015), lxml (CVE-2021-4381, CVE-2021-28957, CVE-2020-27783, CVE-2018-19787), ujson (CVE-2022-31117, CVE-2022-31116, CVE-2021-45958), python-ldap (CVE-2021-46823)

Simple examples of commonly used functions

Presentation of several functions implemented in Setuphelpers and frequently used to develop WAPT packages.

Testing and manipulating folders and files

Creating a path recursively

Command makepath

makepath(programfiles,'Mozilla','Firefox')

… makes the path variable for C:\Program Files (x86)\Mozilla\Firefox.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=makepath#setuphelpers.makepath

Creating and destroying directories

Command mkdirs

mkdirs('C:\\test')

… creates the directory C:\test.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=mkdirs#setuphelpers.mkdirs

Command remove_tree

remove_tree(r'C:\tmp\target')

… destroys the directory C:\tmp\target.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=remove_tree#setuphelpers.remove_tree

Checking if a path is a file or a folder

Command isdir

isdir(makepath(programfiles32,'software')):
    print('The directory exists')

… checks if C:\Program Files (x86)\software is a directory.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=isdir#setuphelpers.isdir

Command isfile

isfile(makepath(programfiles32,'software','file')):
    print('file exist')

… checks if C:\Program Files (x86)\software\file is a file.

Hint

For more informations or to learn more on arguments on that function,* please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=isfile#setuphelpers.isfile

Check if a directory is empty

Command dir_is_empty

dir_is_empty(makepath(programfiles32,'software')):
    print('dir is empty')

… checks that directory C:\Program Files (x86)\software is empty.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=dir_is_empty#setuphelpers.dir_is_empty

Copying a file

Command filecopyto

filecopyto('file.txt',makepath(programfiles32,'software'))

… copies file.txt into the C:\Program Files (x86)\software directory.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=filecopyto#setuphelpers.filecopyto

Copying a directory

Command copytree2

copytree2('sources','C:\\projet')

… copies the sources folder into the C:\projet directory.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=copytree2#setuphelpers.copytree2

Retrieving the version of a file

Command get_file_properties

get_file_properties(makepath(programfiles32,'InfraRecorder','infrarecorder.exe'))['ProductVersion']

… shows package properties.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=get_file_properties#setuphelpers.get_file_properties

Manipulating registry keys

Checking the existence of a registry key

Command registry_readstring

if registry_readstring(HKEY_LOCAL_MACHINE, "SOFTWARE\\Google\\Update\\Clients\\{8A69D345-D564-463c-AFF1-A69D9E530F96}", 'pv'):
    print('key exist')

… checks if registry key {8A69D345-D564-463c-AFF1-A69D9E530F96} exists in registry path SOFTWARE\Google\Update\Clients of HKEY_LOCAL_MACHINE.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=registry_readstring#setuphelpers.registry_readstring

Showing the value of a registry key

Command registry_readstring

print(registry_readstring(HKEY_LOCAL_MACHINE, r'SOFTWARE\Google\Update\Clients\{8A69D345-D564-463c-AFF1-A69D9E530F96}', 'pv'))

… reads the value {8A69D345-D564-463c-AFF1-A69D9E530F96} stored in the registry path SOFTWARE\Google\Update\Clients of HKEY_LOCAL_MACHINE.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=registry_readstring#setuphelpers.registry_readstring

Modifying the value of a registry key

Command registry_setstring

registry_setstring(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows Live\\Common",'TOUVersion','16.0.0.0', type=REG_SZ)

… modifies the value of the registry key TOUVersion stored in the registry path SOFTWARE\Microsoft\Windows Live of HKEY_CURRENT_USER.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=registry_setstring#setuphelpers.registry_setstring

Creating and destroying shortcuts

create_desktop_shortcut/ remove_desktop_shortcut

Command create_desktop_shortcut

create_desktop_shortcut(r'WAPT Console Management',target=r'C:\Program Files (x86)\wapt\waptconsole.exe')

… creates the shortcut WAPT Console Management into C:\Users\Public directory pointing to C:\Program Files (x86)\wapt\waptconsole.exe; the shortcut is available for all users.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=create_desktop_shortcut#setuphelpers.create_desktop_shortcut

Command remove_desktop_shortcut

remove_desktop_shortcut('WAPT Console Management')

… deletes the WAPT Console Management shortcut from the folder C:\Users\Public; the shortcut is deleted for all users.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=remove_desktop_shortcut#setuphelpers.remove_desktop_shortcut

create_user_desktop_shortcut/ remove_user_desktop_shortcut

Hint

These functions are used in session_setup context

Command create_user_desktop_shortcut

create_user_desktop_shortcut(r'WAPT Console Management',target=r'C:\Program Files (x86)\wapt\waptconsole.exe')

… creates the shortcut WAPT Console Management on user desktop pointing to C:\Program Files (x86)\wapt\waptconsole.exe.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=create_user_desktop_shortcut#setuphelpers.create_user_desktop_shortcut

Removing a shortcut for the current user

Command remove_user_desktop_shortcut

remove_user_desktop_shortcut('WAPT Console Management')

… deletes the WAPT Console Management shortcut from the logged in user’s desktop.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=remove_user_desktop_shortcut#setuphelpers.remove_user_desktop_shortcut

Windows environment/ Software/ Services

windows_version

Command windows_version

windows_version()<Version('6.2.0'):

… checks that the Windows version is stricly inferior to 6.2.0.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=windows_version#setuphelpers.windows_version

Visit also Microsoft Windows version number.

iswin64

Command iswin64

if iswin64():
    print('Pc x64')
else:
    print('Pc not x64')

… checks that the system architecture is 64bits.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=iswin64#setuphelpers.iswin64

programfiles/ programfiles32/ programfiles64

Return different ProgramFiles locations

Command programfiles64

print(programfiles64())

… returns native Program Files directory, eg. C:\Program Files (x86) on either win64 or win32 architecture.

print(programfiles())

… returns path of the 32bit Program Files directory, eg. Programs Files (x86) on win64 architecture, and Programs Files on win32 architecture.

print(programfiles32())

user_appdata/ user_local_appdata

Hint

These functions are used with session_setup

Command user_appdata

print(user_appdata())

… returns roaming AppData profile path of logged on user (C:\Users\%username%\AppData\Roaming).

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=user_appdata#setuphelpers.user_appdata

Command user_local_appdata

print(user_local_appdata())

… returns the local AppData profile path of the logged on user (C:\Users\%username%\AppData\Local).

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=user_local_appdata#setuphelpers.user_local_appdata

disable_file_system_redirection

Command disable_file_system_redirection

with disable_file_system_redirection():
    filecopyto('file.txt',system32())

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=disable_file_system_redirection#setuphelpers.disable_file_system_redirection

Disable wow3264 redirection in the current context

get_computername/ get_current_user

Command get_current_user

print(get_current_user())

… shows the currently logged on username

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=get_current_user#setuphelpers.get_current_user

Command get_computername

print(get_computername())

… shows the name of the computer

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=get_computername#setuphelpers.get_computername

Command get_domain_fromregistry

get_domain_fromregistry()

… returns the FQDN of the computer.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=get_domain_fromregistry#setuphelpers.get_domain_fromregistry

installed_softwares/ uninstall_cmd

installed_softwares

Command installed_softwares

installed_softwares('winscp')

… returns the list of installed software on the computer from registry in an array.

[{'install_location': u'C:\\Program Files\\WinSCP\\', 'version': u'5.9.2', 'name': u'WinSCP 5.9.2', 'key': u'winscp3_is1', 'uninstall_string': u'"C:\\Program Files\\WinSCP\\unins000.exe"', 'publisher': u'Martin Prikryl', 'install_date': u'20161102', 'system_component': 0}]

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=installed_softwares#setuphelpers.installed_softwares

uninstalll_cmd

Command uninstall_cmd

uninstall_cmd('winscp3_is1')

… returns the silent uninstall command.

"C:\Program Files\WinSCP\unins000.exe" /SILENT

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=uninstall_cmd#setuphelpers.uninstall_cmd

uninstalling software

for soft in installed_softwares('winscp3'):
    if Version(soft['version']) < Version('5.0.2'):
        run(WAPT.uninstall_cmd(soft['key']))
  • for each item of the list return by installed_softwares containing keyword winscp;

  • if the version is lower than 5.0.2;

  • then uninstall using the uninstall_cmd and specifying the corresponding uninstallkey;

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://dev.tranquil.it/sphinxdocs/source/setuphelpers.html?highlight=uninstall_cmd#setuphelpers.uninstall_cmd

killalltasks

Command killalltasks

killalltasks('firefox')

… kills the process named Firefox.

Hint

For more informations or to learn more on arguments on that function, please visit official Setuphelpers reference documentation:

https://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=killalltasks#setuphelpers.killalltasks

Using control file fields

def setup():
    print(control['version'])

… shows the version value from the control file.

def setup():
    print(control['version'].split('-',1)[0])

… shows the software version number without the WAPT version number from the control file.

Calling WAPT actions in a WAPT package

Installing a package

Command install

WAPT.install('tis-scratch')

… installs tis-scratch on the computer.

Removing a package

Command remove

WAPT.remove('tis-scratch')

… uninstalls tis-scratch from the computer.

Forgeting a package

Command forget_packages

WAPT.forget_packages('tis-scratch')

… informs WAPT to forget tis-scratch on the selected computer.

Hint

If the desired result is to remove tis-scratch, you should either reinstall the package (wapt-get install "tis-scratch") then remove it (wapt-get remove "tis-scratch"), either removing it manually from the Control Panel menu Add/ Remove Programs.