Get et Set d'une variable Windows

Get et Set d'une variable Windows

Messagepar Michael DELIQUE » 19 Oct 2008 à 13:27

Code : Tout sélectionner
Function WindowsGetVariable(wVariable As String) As String
   'cette fonction renvois le contnue d'une variable windows ex %USERNAME%
   
   'Déclaration variable
   Dim vrShell As Variant
   Dim Session As NotesSession
'   Dim vrSysEnv As Variant
   
   On Error Goto ErreurHandle
   
   If Trim(wVariable) = "" Then
      WindowsGetVariable = ""
      Exit Function
   End If
   
   Set Session = New NotesSession
   
   If Session.NotesBuildVersion<190 Then
      'inférieur à la version R6
      Set vrShell = CreateObject("WScript.Shell")
      WindowsGetVariable = vrShell.ExpandEnvironmentStrings(wVariable)
     
   'si ça ne marche pas utiliser cette version du code
'   Set vrSysEnv = vrShell.Environment("SYSTEM")
'   WindowsGetVariable = vrSysEnv(wVariable)
     
      Set vrShell = Nothing
'   Set  vrSysEnv = Nothing
     
   Else
      WindowsGetVariable = Environ$(wVariable)
   End If
   
   Exit Function
ErreurHandle:
   Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   WindowsGetVariable = ""
   Exit Function
End Function
Cordialement

Michael (SMS-Phobique)
----------------------------
"La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi."
Albert EINSTEIN
Avatar de l’utilisateur
Michael DELIQUE
Administrateur
Administrateur
 
Message(s) : 12183
Inscrit(e) le : 16 Déc 2004 à 10:36
Localisation : Paris/Cergy

Messagepar Michael DELIQUE » 19 Oct 2008 à 13:29

Code : Tout sélectionner
Public Sub WindowsSetVariable(wVariable As String, wValeur As String)
      'Déclaration variable
   Dim vrShell As Variant
   
   On Error Goto ErreurHandle
   
   If Trim(wVariable) = "" Then
      Exit Sub
   End If
   
'   If Trim(wValeur) = "" Then
'      Exit Sub
'   End If
   
   Set vrShell = CreateObject("WScript.Shell")
   vrShell.Environment("PROCESS").Item(wVariable) = wValeur
   
   Set vrShell = Nothing
   Exit Sub
ErreurHandle:
   Msgbox "("+Structure_Log+" : "+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   Set Session = New NotesSession
   Call Error_LOG(Session.CurrentDatabase,Cstr(Session.Username),Cstr(Now),Structure_Log,Cstr(Getthreadinfo(10)),Cstr(Getthreadinfo (1)),Cstr(Err),Cstr(Error),Cstr(Erl))
   
   Exit Sub
End Sub
Cordialement

Michael (SMS-Phobique)
----------------------------
"La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi."
Albert EINSTEIN
Avatar de l’utilisateur
Michael DELIQUE
Administrateur
Administrateur
 
Message(s) : 12183
Inscrit(e) le : 16 Déc 2004 à 10:36
Localisation : Paris/Cergy


Retour vers Importation/Exportation vers d'autres applications