Announcement

Collapse
No announcement yet.

Problem with Script Finding User on Computer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Script Finding User on Computer

    In using Joel's script posted in 2003, i get the same result everytime i run the tool. Answer is " User is most likely not logged on anywhere" Here is the code. Any suggestions????

    '************* Begin Script Here *********
    '================================================= =========================
    '
    ' VBScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT(TM)
    '
    ' NAME: FindUser.vbs
    '
    ' AUTHOR: Joel Thoreson , USAALS / AEPCO
    ' DATE : 5/6/2003
    '
    ' COMMENT: Finds a user on the domain.
    '
    '================================================= =========================

    Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
    Dim WshNetwork : Set WshNetwork = WScript.CreateObject("WScript.Network")
    Dim objArgs : Set objArgs = WScript.Arguments ' create object with collection
    Dim fso : Set fso = WScript.CreateObject("Scripting.FilesystemObject")
    Const ForReading=1, ForWriting=2


    If objArgs.Count >= 1 Then
    strUserName = objArgs(0) 'assign the passed user name to a variable
    Else 'quit the script, no variable given, or too many variables passed
    strUserName = InputBox("Enter the name of the individual you wish to query",,WshNetwork.UserName)
    If strUserName = "" Then WScript.Quit
    End If

    If IsNull(strUserName) OR strUserName = "" Then WScript.Quit

    OutputFilePath = "c:\ip1.txt"

    ' Flush the cache
    WshShell.Run "cmd /c nbtstat.exe -R", 2, False
    WScript.Sleep 1000
    ' Send a message to the user
    WshShell.Run "cmd /c net send " & strUserName & " Test locator message.", 2, True
    WScript.Sleep 1000
    ' check the local machines cache, looking for UNIQUE
    WshShell.Run "cmd /c nbtstat.exe -c | find ""UNIQUE"" > " & OutputFilePath, 2, True
    WScript.Sleep 1000

    On Error Resume Next

    Dim objFile : Set objFile = fso.OpenTextFile(OutputFilePath, ForReading)
    Dim strIPAddress : strIPAddress = Trim(Mid(objFile.ReadLine,42,15)) 'read the line

    ' Nobody home
    If Err.Number <> 0 Then
    WshShell.Popup "User '" & UCASE(strUserName) & "' is most likely not logged on anywhere.", 8, "User not found"
    objFile.Close
    fso.DeleteFile(OutputFilePath)
    WScript.Quit
    End If
    objFile.Close

    WshShell.Run ("cmd /c nbtstat.exe -A " & strIPAddress & " > " & OutputFilePath)
    WScript.Sleep 1000

    Set objFile = fso.OpenTextFile(OutputFilePath, ForReading)

    Do While objFile.AtEndOfStream <> True
    aline=Trim(objFile.Readline) 'read a line
    SearchString = "<20>" '20 says file sharing is installed and enabled. See Below!!
    MyPos = Instr(1, aline, SearchString, 1) ' A textual comparison starting at
    If MyPos <> 0 Then
    strComputerName = Trim(Left(aline, (MyPos-1)))
    MsgBox "Machine Name: " & strComputerName
    End If
    Loop

    objFile.Close
    Set objFile = Nothing
    fso.DeleteFile(OutputFilePath)

    ' when running nbtstat, these are the codes
    '00 Base computer name and Workgroups
    '01 Master Browser
    '03 Message Alert service (name of logged in user)
    '20 Resource Sharing `server service` name
    '1B Domain master-browser name
    '1C Domain controller name
    '1E Domain/workgroup master browser election announcement
    '**************** End Script Here *********
Working...
X