Welcome !
         

 Search domain to find which computer a user is logged on to

Author Message
nik1420

  • Total Posts : 73
  • Scores: 0
  • Reward points : 0
  • Joined: 12/19/2007
  • Status: offline
Search domain to find which computer a user is logged on to Friday, February 01, 2008 4:47 AM (permalink)
0
This script here searches the domain to locate where a user might be logged on to.
While this script works, at least I think it does, I have 2 questions.
1- when running, there are multiple dos windows that open and close. This could freak some other admins out.
  How do I hide these windows?
2- There are over 5000 computers to search in the domain. How do I search a specific OU?
 
TIA
 
Here is the script-
 
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) - 1)
      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", "")
End If
Loop
 

 
 
#1
    dm_4ever

    • Total Posts : 3712
    • Scores: 91
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    RE: Search domain to find which computer a user is logged on to Friday, February 01, 2008 1:30 PM (permalink)
    0
    If you have your script run with CScript instead of WScript then you won't see the prompts....look at one of the recent posts and you'll see a function that will detect if the script was executed with WScript and if so...relaunch it with CScript.

    As for your second questions...yes you can have it look at an OU...look for LDAP...there's plenty of examples on the web and in the "post a script" section on this site.
    dm_4ever

    My philosophy: K.I.S.S - Keep It Simple Stupid
    Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
    Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      nik1420

      • Total Posts : 73
      • Scores: 0
      • Reward points : 0
      • Joined: 12/19/2007
      • Status: offline
      RE: Search domain to find which computer a user is logged on to Friday, February 08, 2008 2:30 AM (permalink)
      0
      thanks dm.. I should have known to run it in cscript.  I did run the script to see what would happen, without adding the LDAP line and the script returned an error - Runtime error: invalid procedure call or argument: 'right'
       
      The error is in reference to the line
             strIP = Right(strOutput, (Len(strOutput) - intPosition) - 1)
       
      I searched the web and there was a suggestion to add   & "" to the end, but that didn't work.
       
      Any suggestions on this error?
       
       
      I'm still trying to understand what the script is actually doing? So I haven't put the LDAP line in it yet, because I really don't know where to.  I understand it searches the WINS database for the username, but what does it search in the computers to see who is logged on?
       
      Thanks for all help provided.
       
      #3
        ebgreen

        • Total Posts : 9102
        • Scores: 160
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        RE: Search domain to find which computer a user is logged on to Monday, February 11, 2008 2:49 AM (permalink)
        0
        Change this:
         
        strIP = Right(strOutput, (Len(strOutput) - intPosition) - 1)

         
        to this:
         
        WScript.Echo "strOutput = " & strOutput
        strIP = Right(strOutput, (Len(strOutput) - intPosition) - 1)

         
         
        And I think you will find that strOutput is empty.
        Stop the Help Vampires: http://slash7.com/2006/12/22/vampires/
        VB is NOT VB.Net which is NOT VBA which is NOT VBScript
         
        #4
          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2014 ASPPlayground.NET Forum Version 3.9