What is running and where

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

What is running and where

Post by kpassaur » Mon Apr 13, 2009 11:50 am

I thought this maybe useful to some. It is a script that allows a user to search the network to see where a particular applicaion is running. I put in some remarks so that it would be a little more usefull to beginners.

Copy and paste from here down

/*
This script uses NET.EXE and TASKVIEW.EXE to cycle through each
PC on the network and check to see if a given application is running.
Both these programs come on an XP installation.
Just add the UserName, Password and Process and let it run.
*/

// Get the current PC name as Tasklist has a different command for the current PC
Let>currentpc=%COMPUTER_NAME%

//Enter user name and password for login, usually administrator
Let>UserName=
Let>Password=
Let>Process=

//Delete Last Results
DeleteFile>%TEMP_DIR%localpcs.txt

//Get List of PC's on the Network
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
RunProgram>cmd /c NET.EXE VIEW > "%TEMP_DIR%localpcs.txt"

//Read the list of PC's
Let>k=1
Label>start
ReadLn>%TEMP_DIR%localpcs.txt,k,line
If>line=##EOF##,finish
Position>\\,%line%,1,tl
If>%tl%=1,getline
Let>k=k+1
Goto>start
Label>finish


SRT>getline
//Parse the line to get PC Name only
Position> ,%line%,1,endpos
Sub>endpos,3
MidStr>%line%,3,endpos,compname
//Send results to TASKLIST
GoSub>instance
END>getline

SRT>instance
//Create Command line sent to Local PC
If>%compname%=%COMPUTER_NAME%
Let>testthis=tasklist /S %compname% /FI "IMAGENAME eq %Process%" > %TEMP_DIR%running.txt
Else
//Create Command line sent to Remote PC
Let>User=%compname%\%UserName%
DeleteFile>%TEMP_DIR%running.txt
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Let>testthis=tasklist /S %compname% /u "%User%" /p "%Password%" /FI "IMAGENAME eq %Process%" > %TEMP_DIR%running.txt
Endif

//Execute the Command to see if it is running
Run>cmd /c %testthis%
//Read the Results from TASTLIST
ReadFile>%TEMP_DIR%running.txt,renresult
Length>renresult,tr
If>tr>1
MDL>%Process% is running on %CRLF%%CRLF%%compname%%CRLF%%CRLF%%renresult%
Else
MDL>%Process% is not running on %CRLF%%CRLF%%compname%
Endif

END>instance

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts