1

I have a list of machine names from my network that I have put in a batchfile to run through the list and show me who is logged onto each.

psloggedon \\machineA
psloggedon \\machineB
psloggedon \\machineC
psloggedon \\machineD
psloggedon \\machineE
psloggedon \\machineF
...

Psloggedon works fine, however when it hits a machine that isnt actually on the network, it hangs for a good 30 - 60 seconds before moving onto the next machine...I was just wondering if there was any way to speed this up so that if it hits a machine that isnt on the network, it moves onto the next machine in the list much quicker.

I have read in other places that this could be possible by adding a ping -n loop into the command... but how?

user60707
  • 19
  • 2

4 Answers4

1

In your case it would be the right thing do use ping command.

Start.cmd

FOR /F %%x in (c:\temp\pclist.txt) do call ping_psloggedon.cmd %%x

ping_psloggedon.cmd

ping -n 1 -i 200 -w 130 %1
if errorlevel 1 goto exit
c:\temp\pstools\psloggedon.exe \\%1
:exit

pclist.txt

PCNAME1
PCNAME2
PCNAME3
1

I dont know a way to do that in Dos. Put you can use Autoit to get a "clear" list. http://www.autoitscript.com

Install Autoit then you can use this script. You have to use newest psloggedon.exe (1.34)

Save the script as "NAME.au3" (NAME what ever you want) file.

Example:

c:\NAME.au3
c:\pclist.txt
c:\pstools\psloggedon.exe

#include <Constants.au3>
Dim $line, $line2, $file, $icount, $reg, $reg2, $reg3
$file = FileOpen("pclist.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error Then ExitLoop
    $reg3 = ""
    $reg2 = ""
    $reg = ""
    If Ping($line, 200) Then
        $reg = @ComSpec & ' /C "' & @ScriptDir & "\pstools\psloggedon.exe -l -x \\" & $line & '"'
        $reg = Run($reg, "", @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD)
        While 1
            $reg2 = StdoutRead($reg)
            If @error Then ExitLoop
            If $reg2 Then
                $reg3 &= $reg2
            EndIf
        WEnd
        If StringInStr($reg3, "Error") Then
            $reg = "Error"
        ElseIf StringInStr($reg3,"No one is logged") Then
                $reg = "No one is logged on locally."
        Else
                $reg = StringTrimLeft($reg3, StringInStr($reg3, Chr(13), "", 3))
                $reg = StringTrimLeft($reg, StringInStr($reg, "\"))
                $reg = StringTrimRight($reg, StringLen($reg) - StringInStr($reg, Chr(13)))
                $reg = StringStripWS($reg, 8)
        EndIf
        $icount += 1
        $line2 &= $icount & @TAB & $line & @TAB & $reg & @CRLF
    EndIf
    TrayTip("Psloggedon", $icount & " " & $line & " User: " & $reg, 10)
WEnd
FileClose($file)
ConsoleWrite($line2)
FileDelete("C:\output.txt")
FileWrite("C:\output.txt", $line2)
ShellExecute("C:\output.txt")
0

Just add >> c:\output to c:\temp\pstools\psloggedon.exe \%1

ping -n 1 -i 200 -w 130 %1
if errorlevel 1 goto exit
c:\temp\pstools\psloggedon.exe \\%1 >> C:\output.txt
:exit

Now every time you start the start.cmd the results would be added to c:\output.txt

If you want you can add echo LoggedonUsers > c:\output.txt to start.cmd to get a clean output.txt at start.

echo LoggedonUsers > c:\output.txt
FOR /F %%x in (c:\temp\pclist.txt) do call ping_psloggedon.cmd %%x

What do you mean with "Would this also be ERRORLEVEL statement ?"

0

Thanks again mate :)

That works well too ! is it possible to output just the value of the machine name ? as opposed to all of the other text that i currently get in the output file..

So in output.txt currently it displays this...

Connecting to Registry of \LT013131...

Users logged on locally: 19/11/2010 09:08:05 domain name\userid Users logged on via resource shares: 19/11/2010 11:44:17 domain name\userid

Is there anyway so that it just runs through the list and outputs just LT013131 ?

So once the script completes I would just have a list of machine names ..

Thanks :)