VB6 recuperer le nom dutilisateur sous windows

VB6 recuperer le nom dutilisateur sous windows - VB/VBA/VBS - Programmation

Marsh Posté le 05-02-2003 à 22:34:43    

comment recuperer le nom dutilisateur connecté sous nimporte kel windows ?
 
merci


Message édité par rik le 05-02-2003 à 22:35:55
Reply

Marsh Posté le 05-02-2003 à 22:34:43   

Reply

Marsh Posté le 05-02-2003 à 22:39:32    


Private Const UNLEN As Integer = 256
Private Declare Function GetUserNameEx _
                Lib "advapi32.dll" _
                Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 
Private Function GetUserName() As String
    Dim strUserName         As String
    Dim lSize               As Long
    Dim lValue              As Long
 
    ' Get Username
    lSize = UNLEN
 
    strUserName = Space$(UNLEN)
    lValue = GetUserNameEx(strUserName, lSize)
    If lValue > 0 Then
        GetUserName = Mid$(strUserName, 1, lSize - 1)
    Else
        GetUserName = ""
    End If
End Function


 
j'ai pas compilé mais bon ça doit marcher ;)


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
Reply

Marsh Posté le 05-02-2003 à 22:42:15    

merci ! ton code marche

Reply

Marsh Posté le 06-02-2003 à 09:50:49    

Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'Pour obtenir le nom de l'ordinateur
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'Pour obtenir le nom de l'utilisateur
 
Public Function Get_UserName() As String
'Retourne le nom de l'utilisateur
 
Dim StrUser As String
Dim LTemp As Long
 
    StrUser = String$(255, vbNullChar)
    LTemp = GetUserName(StrUser, Len(StrUser))
    LTemp = InStr(StrUser, Chr$(0)) - 1
    Get_UserName = Mid(StrUser, 1, LTemp)
         
End Function
 
Public Function Get_ComputerName() As String
'Retourne le nom de l'utilisateur
 
Dim StrComputer As String
Dim LTemp As Long
 
    StrComputer = String$(255, vbNullChar)
    LTemp = GetComputerName(StrComputer, Len(StrComputer))
    LTemp = InStr(StrComputer, Chr$(0)) - 1
    Get_ComputerName = Mid(StrComputer, 1, LTemp)
         
End Function


---------------
Des bons sites pour Delphi? http://forum.hardware.fr/forum2.php3?post=16838&cat=10 -- informaticien -- http://www.z0rglub.com/phpwebgallery/ -- Delphi :love:
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed