Page 1 sur 1

Login UserName

MessagePublié: 06 Nov 2007 à 09:01
par Michael DELIQUE
Code : Tout sélectionner
Public Function LoginUserName As String
   
%REM
'Variables API pour la fonction LoginUserName
Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" ( Byval lpName As String, Byval lpUserName As String, lpnLength As Long ) As Long
%END REM
   
   'Declaration Variable
   Const lpnLength  = 255       
   Dim status As Integer         
   Dim lpName As String
   Dim lpUserName As String         
   
   On Error Goto ErreurLoginUserName
   
   lpUserName = Space$ (lpnLength + 1 )         
   status = WNetGetUser(lpName, lpUserName, lpnLength)         
   If status = 0 Then                 
      LoginUserName = Left$ (lpUserName, Instr (lpUserName, Chr (0)) - 1 )               
   Else                 
      LoginUserName = ""
   End If         
   
   Exit Function
ErreurLoginUserName:
   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 !"
   LoginUserName = ""
   Exit Function
End Function