Hi friends,
Im new to API. I want to know the user name who has logged in the machine. What API should I use?
Pls help!!!
Cheers
Parasuraman
Printable View
Hi friends,
Im new to API. I want to know the user name who has logged in the machine. What API should I use?
Pls help!!!
Cheers
Parasuraman
Use the GetUserName API:
Code:Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Since you are new to API stuff I add this too..
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Your_Sub()
Dim strUSerName As String
'Create a buffer
strUserName = String(100, Chr$(0))
'Get the username
GetUserName strUserName, 100
'strip the rest of the buffer
strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
MsgBox "Hello " + strUserName
End Sub
Thanx alot CyeberCarsten and Kumar
Its working excellent.
Thanx alot again
Parasuraman