Le forum (ô combien francophone) des utilisateurs de Powerbuilder.
Pages: 1
Bonjour ,
Je suis en train de me cassé la tête a cherche de l'aide sur la fonction SetEnvironmentVariableA() qui doit me permettre de modifier ma variable d'environnement PATH.
Quelqu'un de la communauté PB l'a déjà utilisée? si oui, comment?
Merci encore pour votre aide.
Dernière modification par themoyo (20-03-2008 14:39:14)
Hors ligne
Bonjour et
il faut déclarer la fonction externe : (en local ou global)
Function Boolean SetEnvironmentVariableA( string szName, string szValue ) Library "kernel32.dll"
ensuite pour l'appel :
Boolean lb_ok lb_ok = SetEnvironmentVariableA( 'PATH', 'chemins' ) // test de retour lb_ok
Hors ligne
Déja merci pour l'info, c'est gentil.
Sinon, je me pose la question suivante :
es que avec le code suivant, l'ancien PATH va étre ecrasé oubien concaténer avec le nouveau chemin?
ErAsORz a écrit:
Code: pb
Boolean lb_ok lb_ok = SetEnvironmentVariableA( 'PATH', 'chemins' ) // test de retour lb_ok
Pérsonnélement, je pense qu'il va l'ecraser => se qui m'obiligerait donc d'utiliser GetEnvironmentVariableA.
Si c'est le cas, comment faire
Hors ligne
themoyo a écrit:
es que avec le code suivant, l'ancien PATH va étre ecrasé oubien concaténer avec le nouveau chemin?
fais le test...
themoyo a écrit:
Pérsonnélement, je pense qu'il va l'ecraser => se qui m'obiligerait donc d'utiliser GetEnvironmentVariableA.
Si c'est le cas, comment faire
// déclaration de la fonction externe Function Long GetEnvironmentVariableA (String lpName, Ref String lpBuffer,Long nSize) Library "kernel32" Alias For "GetEnvironmentVariableA;ansi" // récup du path actuel String ls_path = Space (255) Long ll_l = 255 GetEnvironmentVariableA ('PATH', ls_path , ll_l) // ajout chemins ls_path += ';chemin1;chemin2...' // màj path SetEnvironmentVariableA( 'PATH', ls_path )
Hors ligne
Le code si dessous ne fonctionne pas.
le ls_path reste vide. je ne vois pas pourquoi.
ErAsORz a écrit:
Code: pb
// déclaration de la fonction externe Function Long GetEnvironmentVariableA (String lpName, Ref String lpBuffer,Long nSize) Library "kernel32" Alias For "GetEnvironmentVariableA;ansi" // récup du path actuel String ls_path = Space (255) Long ll_l = 255 GetEnvironmentVariableA ('PATH', ls_path , ll_l) // ajout chemins ls_path += ';chemin1;chemin2...' // màj path SetEnvironmentVariableA( 'PATH', ls_path )
Hors ligne
Alias For
"GetEnvironmentVariableA;ansi"
pour la version pb10 et pb11
sinon ,
FUNCTION uLong GetEnvironmentVariableA(String lpszName, REF String lpszValue, uLong dwcValue) library "Kernel32.dll" CONSTANT Integer MAX_PATH_LEN = 260 // Path can be up to 260 characters String ls_Path ls_Path = Space(MAX_PATH_LEN) // By making the string 260 characters, we're "reserving" 261 bytes of memory GetEnvironmentVariableA("PATH", ls_Path, MAX_PATH_LEN + 1)
Hors ligne
Merci encore pour tout pick ouic.
Pour info:
Lors de la déclaration il ne faut pas oublier le ALIAS FOR "GetEnvironmentVariableA;Ansi" car c'est ce qui ma posé probléme.
Vous trouverez un code qui fonctionne a merveille.
ASTUS : Le premier Get me permet de récupérer la Taille du PATH
FUNCTION uLong GetEnvironmentVariableA(String lpszName, REF String lpszValue, uLong dwcValue) library "Kernel32.dll" ALIAS FOR "GetEnvironmentVariableA;Ansi" Taille = GetEnvironmentVariableA("PATH",ref Path,0) // it's return length of Path Path = space(Taille) // Initialisation of string Path GetEnvironmentVariableA("PATH",ref Path,Taille) // Recup of real Path SetEnvironmentVariableA("PATH",RepSyb + "dll;" + RepSyb + "dll\Debug;" + RepSyb + "bin;" + Path) // Set of Path
Hors ligne
Pages: 1