PDA

Click to See Complete Forum and Search --> : Fndig Compuer name by inputting username


JSabia85
May 16th, 2008, 08:02 PM
Ok so the company I work for has 600+ PC's. I came across a VB script where you enter a username and it returns the computer name that person is on. Here it code: (from http://windowsitpro.com/windowsscripting/article/articleid/40879/find-the-name-of-the-computer-a-user-is-logged-on-to.html)


Option Explicit

Dim objShell, objExec, strUserName, strOutput, intLine
Dim intPosition, strIP, arrEntrySplit, strComputerName, intRemote

Set objShell = CreateObject("WScript.Shell")
strUserName = InputBox("Please enter a user name:" & vbCRLF & vbCRLF & _
"(Press [ENTER] or click [CANCEL] to exit...)", _
"User Computer Name Locator", "")

Do While strUserName <> ""
Set objExec = objShell.Exec("NETSH WINS SERVER \\WinsServerName SHOW NAME " _
& strUserName & " 03")
For intLine = 1 To 4
objExec.StdOut.ReadLine
Next
If objExec.StdOut.ReadLine <> "The name does not exist in the WINS database." Then
For intLine = 1 To 5
objExec.StdOut.ReadLine
Next
strOutput = objExec.StdOut.ReadLine
If Left(strOutput,10) <> "IP Address" Then
strOutput = objExec.StdOut.ReadLine
End If
intPosition = InStr(strOutput, ":")
strIP = Right(strOutput, (Len(strOutput) - intPosition) - 0)
Set objExec = objShell.Exec("NBTSTAT -A " & strIP)
Do While Not objExec.StdOut.AtEndOfStream
strOutput = objExec.StdOut.ReadLine
If InStr(strOutput,"<03>") <> 0 Then
arrEntrySplit = Split(strOutput)
If UCase(arrEntrySplit(4)) <> UCase(strUserName) And _
UCase(arrEntrySplit(4)) <> UCase(strComputerName) And _
UCase(arrEntrySplit(4)) <> strComputerName & "$" Then
strComputerName = strComputerName & UCase(arrEntrySplit(4))
End If
End If
Loop
If strComputerName <> "" Then
MsgBox "The requested user '" & strUserName & _
"' is logged on to: " & strComputerName,,"User Computer Name Locator"
Else
MsgBox "The requested user '" & strUserName & _
"' doesn't appear to logged on to the network. "
End If
Else
MsgBox "The user was not found in the WINS database. ",, _
"User Computer Name Locator"
End If
strComputerName = ""
strUserName = InputBox("Please enter a user name:" & vbCRLF & vbCRLF & _
"(Press [ENTER] or click [CANCEL] to exit...)", _
"User Computer Name Locator", "")
Loop



Here is the thing, the scrip works really well but unfortunately, it only works with Windows 2000 based PC's. It does not work for Windows XP based PC's. Could somebody help me fix it up where it would work on both 2000 and XP systems?

mendhak
May 17th, 2008, 02:33 PM
What happens when you run it on an XP machine, what error do you get and what line does it happen on?