[Wapt] Créer une variable système lors de l'installation
Hubert TOUVET
htouvet at tranquil.it
Wed Apr 9 18:38:08 CEST 2014
Le 09/04/2014 16:53, "Frédéric VOLPI (Rectorat)" a écrit :
> Bonjour,
> Quelle(s) instruction(s) faut-il utiliser dans le script
> d'installation pour créer une variables systèmes ?
> Merci
>
Tout dépend si c'est une variable d'environnement persistante, ou juste
nécessaire pour l'installation en cours.
variable non persistante :
import os
def install():
os.environ['TEST'] = 'une variable'
print run('echo %TEST%')
Fonction pour variable persistante (je l'ajoute aux setuphelpers... ):
def set_environ_variable(name,value,type=REG_EXPAND_SZ):
r"""Add or update a system wide persistent environment variable
>>> set_environ_variable('WAPT_HOME','c:\\wapt')
>>> import os
>>> os.environ['WAPT_HOME']
'c:\\wapt'
"""
with
reg_openkey_noredir(HKEY_LOCAL_MACHINE,r'SYSTEM\CurrentControlSet\Control\Session
Manager\Environment',
sam=KEY_READ | KEY_WRITE) as key:
reg_setvalue(key,name,value,type=type)
# force to get new environ variable, as it is not reloaded immediately.
os.environ[name] = value
win32api.SendMessage(win32con.HWND_BROADCAST,win32con.WM_SETTINGCHANGE,0,'Environment')
Hubert
More information about the WAPT
mailing list