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