Zjištění aktuálního přihlášeného uživatele

Postup:
V deklarační části formuláře zapište:

Private Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long

Na formulář přidejte tlačítko. Na událost Click tlačítka:

Private Sub Command1_Click()

   Dim s As String
   Dim cnt As Long
   Dim dl As Long
   Dim CurUser As String

   cnt = 199
   s = String$(200, 0)
   dl = GetUserName(s, cnt)
   If dl <> 0 Then CurUser = Left$(s, cnt) Else CurUser = ""
   MsgBox CurUser

End Sub
   

Zpět

Autor: The Bozena