Need to find username for a specific computer on Network

I have a windows network I help administer, and our database of usernames/computers is out of sorts. I have 2 specific computers with unauthorized software on the NIPR network, that I cannot remote into. I need to find out what username is logged onto those computers. Is there a DOS prompt command that will allow me to find a username logged onto the computers, based on having the computer name and IP address?

Who is Participating?
bsharathConnect With a Mentor Commented:
This is one excellent Hts file which when entered a machine name or ip will get the logged in user details
Save the code to filename.hta.

<title>Login Details of a Machine</title>
     APPLICATIONNAME="Login Details"

<script language="VBScript">

Sub Window_onLoad
      Me.ResizeTo 400,300
    Me.MoveTo ((Screen.Width / 2) - 200),((Screen.Height / 2) - 150)
End Sub

Sub Default_Buttons
      If Window.Event.KeyCode = 13 Then
      End If
End Sub

Sub Get_Login_Details
      strComputer = txt_computer.value
      if strComputer = "" Then
            msgbox "Please enter a computer name or IP Address",vbOKOnly,"No Computer Name or IP Address"
            Exit Sub
      End If
      If Ping(strComputer) = False Then
        msgbox strComputer & " did not respond to ping. No action could be taken.",vbOkOnly, "Cannot continue script."
        Exit Sub
      End If      
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      Set colComputer = objWMIService.ExecQuery _
          ("Select * from Win32_ComputerSystem")
      Set colComputerIP = objWMIService.ExecQuery _
          ("Select * from Win32_NetworkAdapterConfiguration")
      Set colSystemInfo = objWMIService.ExecQuery _
          ("Select * from Win32_OperatingSystem",,48)
      For Each objComputer in colComputer
          strUserName = "User Name: " & objComputer.UserName
          strHostName = "Host Name: " & objComputer.Name
      For Each IPConfig in colComputerIP
            If Not IsNull(IPConfig.IPAddress) Then
              For intIPCount = LBound(IPConfig.IPAddress) _
                  to UBound(IPConfig.IPAddress)
                      strIPAddress = strIPAddress & "IP Address: " & IPConfig.IPAddress(intIPCount) & "~"
            end if
      If Right(strIPAddress, 1) = "~" Then
            strIPAddress = Left(strIPAddress, Len(strIPAddress) - 1)
      End If
      strIPAddress = Replace(strIPAddress, "~", vbCrLf)
      For Each objItem in colSystemInfo
           strOS_Caption = "Caption: " & objItem.Caption
           strOS_SPVersion = "SP Version: " & objItem.CSDVersion
           strOS_VerNumber = "Version Number: " & objItem.Version
      MsgBox strUserName & vbcrlf & strHostName & vbcrlf & _
           strIPAddress & vbcrlf & strOS_Caption & vbcrlf & _
           strOS_SPVersion & vbcrlf & strOS_VerNumber, vbOKOnly, "Login Details"
End Sub

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
            Ping = False
      End If
End Function


<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
      <table width='80%' height = '100%' align='center' border='0'>
            <tr height='20%'>
            <tr height='10%'>
                  <td align='center'>
                        Computer name or IP Address:
            <tr height='20%'>
                  <td align='center'>
                        <input type="text" value="" name="txt_computer" maxlength='15' size='16'>
            <tr height='30%'>
                  <td align='center'>
                        <input type="button" value="Check Machine" name="btn_logindetails"  onClick="Get_Login_Details">
            <tr height='20%'>



Hope this helps...
Pete LongTechnical ConsultantCommented:
Find out who's logged In and where.

Option 1 (The Lazy GUI Way)

Get hold of a copy of Angry IP Scanner

Run it > select Options > Select Columns > add the "User Name" Column > then type in the lowest and highest IP address on your LAN and clickStart

Option 2 (From Command Line)
NBTscan is a program for scanning IP networks for NetBIOS name information. It sends NetBIOS status query to each address in supplied range and lists received information in human readable form. For each responded host it lists IP address, NetBIOS computer name, logged-in user name and MAC address.

This program is a successor of a perl script with the same name and does essentially the same thing, being much faster though. NBTscan produces a report like that:

IP address          NetBIOS Name     Server    User                            MAC address
---------------------------------------------------------------------------------------------------------------------------       MYCOMPUTER                    JDOE                        00-a0-c9-12-34-56        WIN98COMP       <server>  RROE                       00-a0-c9-78-90-00    DPTSERVER       <server>  ADMINISTRATOR    08-00-09-12-34-56

First column lists IP address of responded host. Second column is computer name. Third column indicates if this computer shares or is able to share files or printers. For NT machine it means that Server Service is running on this computer. For Windows 95 it means that "I want to be able to give others access to my files" or "I want to be able to allow others to print on my printer(s)" checkbox is ticked (in Control Panel/Network/File and Print Sharing). Most often it means that this computer shares files. Third column shows user name. If no one is logged on from this computer it is same as computer name. Last column shows adapter MAC address.


If you are simply trying to find who is logged into a partticualr Server od PC then try the following commands

net statistics server
net statistics workstation
net user

Or if its only one machine

Copt and paste the code below save it as whois.vbs and run it

-------Cut Below---------
Dim sComputer
Dim oWMI, oComputer
Dim colComputer

sComputer = InputBox("Enter The Computer Name", "Return User","",1500)

Set oWMI = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set colComputer = oWMI.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each oComputer in colComputer
    MsgBox oComputer.UserName,,"Return User"
--------Cut Above-------


To see who is logged on to a particular PC use WilliamK99,


WilliamK99Author Commented:
Excellent advice, worked like a charm...Would give an A+ if I could.
WilliamK99Author Commented:
That was a brilliant program, thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.