Page 1 sur 1

Récupérer le nom d'utilisateur Windows

MessagePublié: 25 Oct 2011 à 11:20
par lebanner
Bonjour,

Est ce qu'il existe une fonction qui permet de récupérer le nom d'utilisateur Windows (en LS) ?

Je regarder dans l'aide mais je n'ai pas encore trouvé mon bonheur

J'ai trouvé ceci sur le site :
http://forum.dominoarea.org/connatre-le-login-reseau-de-lutilisateur-t12926.html
mais est ce qu'il y a plus simple ? sans forcement installer une DLL.....

Merci d'avance
Cordialement

MessagePublié: 25 Oct 2011 à 11:24
par lebanner
Non, c'est bon, j'ai trouvé mon bonheur.

Voici le code :
Dim winun As String
winun = Environ("username")

Cordialement

MessagePublié: 25 Oct 2011 à 11:36
par Michael DELIQUE
salut

sinon tu as ça

Code : Tout sélectionner
Public Function WindowsUserName As String

   Dim vrShell As Variant
   
   On Error Goto CatchError
   
   Set vrShell = CreateObject("WScript.Shell")
   WindowsUserName = vrShell.ExpandEnvironmentStrings("%username%")
   
   Set vrShell = Nothing
   
   Exit Function
CatchError:
   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 !"
   WindowsUserName = ""   
   Exit Function
End Function

MessagePublié: 25 Oct 2011 à 11:40
par lebanner
Michael DELIQUE a écrit:salut

sinon tu as ça

Code : Tout sélectionner
Public Function WindowsUserName As String

   Dim vrShell As Variant
   
   On Error Goto CatchError
   
   Set vrShell = CreateObject("WScript.Shell")
   WindowsUserName = vrShell.ExpandEnvironmentStrings("%username%")
   
   Set vrShell = Nothing
   
   Exit Function
CatchError:
   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 !"
   WindowsUserName = ""   
   Exit Function
End Function


Bonjour Michael,

Oui je l'avais vu mais je trouv ça un peu compliqué.
La fonction Environ$ fonctionne très bien

Merci
Cordialement