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(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=get_file_properties#setuphelpers.properties.

Creating and destroying directories

Command…

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=get_file_properties#setuphelpers.properties

Commande 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:\programfiles32\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=get_file_properties#setuphelpers.properties

Command…

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

… checks if C:\programfiles32\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=get_file_properties#setuphelpers.properties

Check if a directory is empty

Command…

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

… checks that directory C:\programfiles32\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=get_file_properties#setuphelpers.properties

Copying a file

Command…

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

… copies file.txt into the C:\programfiles32\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=get_file_properties#setuphelpers.properties

Copying a directory

Command…

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

… copies the sources folder into the C:\programfiles32\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=get_file_properties#setuphelpers.properties

Retrieving the version of a file

Command…

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.properties

Manipulating registry keys

Checking the existence of a registry key

Command…

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 :file: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…

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 :file: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(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 :file: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(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 file: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('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(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)waptwaptconsole.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

Command…

Removing a shortcut for the current user

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 environnement / Software / Services

windows_version

Command … .. code:: python

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

Microsoft Windows version number : https://msdn.microsoft.com/fr-fr/library/windows/desktop/ms724832

iswin64

Command…

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=get_file_properties#setuphelpers.properties

programfiles / programfiles32 / programfiles64

Return different ProgramFiles locations

Command…

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…

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…

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…

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=get_file_properties#setuphelpers.properties

Disable wow3264 redirection in the current context

get_computername / get_current_user

Command…

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_file_properties#setuphelpers.properties

Command…

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()

… 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('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=get_file_properties#setuphelpers.properties

uninstall_cmd

Command…

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://dev.tranquil.it/sphinxdocs/source/setuphelpers.html?highlight=uninstall_cmd#setuphelpers.uninstall_cmd

Removing software

Command…

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” ;
  • si la version dans la liste est plus petite que 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://www.wapt.fr/en/api-doc-1.5/source/setuphelpers.html?highlight=get_file_properties#setuphelpers.properties

killalltasks

Command…

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=get_file_properties#setuphelpers.properties

Using control file fields

Command…

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

… shows the version value from the control file.

Command…

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…

WAPT.install('tis-scratch')

… installs tis-scratch on the computer.

Removing a package

Command…

WAPT.remove('tis-scratch')

… uninstalls tis-scratch from the computer.

Forgeting a package

Command…

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.