|
-
May 16th, 2008, 08:02 PM
#1
Thread Starter
New Member
Fndig Compuer name by inputting username
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/windowsscrip...ged-on-to.html)
Code:
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?
-
May 17th, 2008, 02:33 PM
#2
Re: Fndig Compuer name by inputting username
What happens when you run it on an XP machine, what error do you get and what line does it happen on?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|