1
votes

I am new to vbscript.

I am running a psloggedon.exe via a vbscript for a total of 25 computers. I need to check the line that says "Users logged on locally" and see if it says "Users logged on locally" or "No one is logged on locally".

If it says a user is logged in, i need to write that out to a text file along with the computer name. If it says no one is logged on, i need to write the computer name out to the same text file and say "available". I'd loop through and have a list of all 25 machines. I cant seem to figure out how to go to that one line and validate what it says.

PsLoggedon v1.34 - See who's logged on
Copyright (C) 2000-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

Users logged on locally:
     2/19/2014 8:56:35 AM       DOMAIN\John.Smith

Users logged on via resource shares:
     2/26/2014 10:09:07 AM      DOMAIN\John.Smith

Code excerpt:

    Dim ObjExec
    Dim strFromProc
    Dim MachineNum


    MachineNum = 1

    Set objShell = CreateObject("WScript.Shell")
    Set ObjExec = objShell.Exec("cmd /K CD F:\QA & LabQwinsta")

    Do

        strFromProc = ObjExec.Stdout.Readall()
        msgbox strFromProc

        document.write(strFromProc)

Thats about as far ive gotten. At this point is just displays everyline in the text file.

2
Show us your code and tell us where the problem is...then we can help you. - aphoria
I don't see that you're even calling PSLOGGEDON. - aphoria
sorry as i have left a detail out. I have a .cmd file that is located at F:\QA\LabQwinsta.cmd. That runs the 25 iterations of PSLOGGEDON. It works correctly and gives output above. I need to parse the output and make decision based on if someone is logged into the machine or not. - Fairbanks

2 Answers

0
votes

You could split the output into an array and then go through it line by line, looking for the text you need.

lines = Split(strFromProc, vbCrLf)
For i = 0 To UBound(lines, 1)
  If lines(i) = "Users logged on locally" Then
    ' Do your stuff
  End If
Next
0
votes

You could use the RegExp object to parse the output from PSLOGGEDON but it's easier to just test for a known string. You can use InStr() or, like in the example below, you can just test the first few characters.

Also, since we'll need a Network object anyway to get the PC name (it's not included in the command's output), we may as well use it to return the username, too, instead of trying to parse it from the output of PSLOGGEDON.

With CreateObject("WScript.Network")
    strPC   = .ComputerName
    strUser = .UserName
End With

If StrComp(Left(strFromProc, 15), "Users logged on") = 0 Then
    MsgBox strUser & " is logged into " & strPC
Else
    MsgBox strPC & " is available"
End If