| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 
 |  
Attribute VB_Name = "RenseignementsReseau"
 
Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
        (ByVal lpBuffer As String, nSize As Long) As Long
 
Declare Function GetUserName Lib "ADVAPI32.DLL" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
 
Const MAX_COMPUTERNAME_LENGTH = &H15
 
Function NomMachine() As String
 
Dim tempStr As String * MAX_COMPUTERNAME_LENGTH
Dim nbcar As Long
 
    nbcar = MAX_COMPUTERNAME_LENGTH + 1
    GetComputerName tempStr, nbcar
    NomMachine = Left$(tempStr, nbcar)
 
End Function
 
Function UserName()
Dim S As String
Dim N As Long
Dim Res As Long
 
    S = String$(200, 0)
    N = 199
    Res = GetUserName(S, N)
    UserName = Left(S, N - 1)
 
End Function
 
Sub test()
    MsgBox NomMachine
    MsgBox UserName
End Sub | 
Partager