Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get NetWork Users or PC's names

Status
Not open for further replies.

jpreciado

MIS
Feb 7, 2004
36
MX
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

Thanks in advance.
 
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

sSize = 255
sBuffer = Space(sSize)
sResult = GetUserName(sBuffer, sSize)
GetUName = Left(sBuffer, sSize - 1)

End Function
 

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 = ""

fnGetUserName = sUser
End Function


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top