Jump to content

VBScript Help


psycho
 Share

Recommended Posts

i am trying to code a vbscript to tell me where a username is logged into on a domain running xp machines and 2k3 svr, here is what i have......can you help?????

'================================================================
'VBScript to find where a user is logged into
'Written by Psycho
'================================================================

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...