Code to find out if anyone is logged into a computer on the network

PappySki

New Member
Joined
May 12, 2009
Messages
12
Greetings,

I've got a macro that references a list of IP Addresses that starts in A2 and then pings each address to provide a status for each IP Address. I would like to add a macro that would check each IP Address and let me know if anyone is currently logged into the machine. It would be nice to know who is logged in, but this isn't necessary.

Thanks

PappySki
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
this is some code I have posted before, pass it a computer name or IP address, set it up as a user defined function and reference it in a cell

Public Function GetUserName(HostName As String)
'
' Returns the Username from the HostName for the computer.
'
' Author Unknown
' Mods Jim Ward, 25 March 2008
' Original version was to return the MAC address from the output text from
' a shell of nbtstat.
' This version uses a more elegent method to extract out the <03> record as a
' single line to the new output file, file is then read in first part extracted
' and file deleted.
'
' This is slow by nature as in a couple of seconds to run it for each hostname
' so if you have many to find and copy the function down be warned as it will
' not give instant results.

'
Dim SH As Object
Dim FSO As Object
Dim TS As Object
Dim Data As String
Dim UserName As String
'
On Error GoTo ErrorHandler

'
'****
' create a scripting shell object, and run our command through it
' if it is an IP address use -A, else for computer name use -a
'****
'
Set SH = CreateObject("wscript.shell")
If InStr(HostName, ".") Then
SH.Run "%comspec% /c nbtstat -A " _
& HostName & " | FIND ""<03>"" | FIND /I /V " & Chr(34) & HostName & Chr(34) & " > c:\nbuser.txt", 0, True
Else
SH.Run "%comspec% /c nbtstat -a " _
& HostName & " | FIND ""<03>"" | FIND /I /V " & Chr(34) & HostName & Chr(34) & " > c:\nbuser.txt", 0, True
End If
Set SH = Nothing
'Stop
'
'****
' open up the results file, should have a single line, extract the username
'****
'
Set FSO = CreateObject("scripting.filesystemobject")
Set TS = FSO.opentextfile("c:\nbuser.txt") 'text stream
UserName = ""
Do While Not TS.AtEndOfStream
Data = UCase(Trim(TS.readline))
UserName = Left(Data, InStr(Data, "<") - 1)
Loop
'
'****
' tidy up before we exit
'****
'
TS.Close
Set TS = Nothing
FSO.deletefile "c:\nbuser.txt"
Set FSO = Nothing
'
GetUserName = UserName
Exit Function
'
ErrorHandler:
GetUserName = "Error in GetUserName function"
End Function
 
Upvote 0
I don't see where this is pulling the IPs from or writing the username. I want it to check the IPs in column A starting in row 2 on Sheet1. I would like it to write the user names in column C starting in row 2, also on Sheet1.
 
Upvote 0
you will have to open the VBA editor, insert a module and paste in my code

you will then in column C or whereever, type =GETUSERNAME(A2) or wherever your data starts
 
Upvote 0
Unfortunately, this doesn't work for me. Turns out nbtstat relies on Netbios which we don't have on our network. Any other ideas?
 
Upvote 0
what network do you have
 
Upvote 0
can you resolve the ping or tracert to an actual computer name, and do you have elevated privs on the network
 
Upvote 0
I've got the privileges. I can run nbtstat -A against an IP and get a NetBIOS table. But the table only includes:

ComputerName <00> Unique Registered
DomainName <00> Group Registered
ComputerName <20> Unique Registered

MAC Address

That's all.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top