How can I get the users logged in to a network or PC's names attached to it?.
I 've been tried with winmgmts Object but I could'nt find how to get logged users or computer names from it this code but I
Public Function CurrentMachineName() As String
Dim lSize As Long
Dim sBuffer As String
sBuffer = Space$(16)
lSize = Len(sBuffer)
If GetComputerName(sBuffer, lSize) Then
CurrentMachineName = Left$(sBuffer, lSize)
End If
'Debug.Print CurrentMachineName
'Stop
End Function
Function GetUName() As String
'Get the currently logged in username
Dim sBuffer As String
Dim sSize As Long
Dim sResult As Long
Private Declare Function GetComputerName Lib "kernel32.dll" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function fnGetComputerName() As String
Dim strCompName As String
Dim rVal As Long
Dim lngLen As Long
strCompName = Space(255)
lngLen = 255
rVal = GetComputerName(strCompName, lngLen)
fnGetComputerName = Left(strCompName, lngLen)
End Function
Public Function fnGetUserName() As String
Dim sUser As String
Dim lpBuff As String * 1024
'Get the Login User Name
GetUserName lpBuff, Len(lpBuff)
sUser = Left$(lpBuff, (InStr(1, lpBuff, vbNullChar)) - 1)
lpBuff = ""
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.