Page 1 sur 1

Get et Set d'une variable Windows

MessagePublié: 19 Oct 2008 à 13:27
par Michael DELIQUE
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

MessagePublié: 19 Oct 2008 à 13:29
par Michael DELIQUE
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