Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect if script already running

Status
Not open for further replies.

wveldeman

MIS
Jan 21, 2004
3
BE
There is something -at first sight very basic- I would like to do: when I start a vbs script, I want to display a warning if this same vbs is already running (to avoid file in use problems etc).

Two options I see:
work with a temporary file created at the start of the vbs and removed at the end of it. Disadvantage: if the script ever crashes, the temporary file will not be removed.

Second option I see is to work with wmi Win32_process: collect all processes on the pc and use string manipulation to see if wscript/cscript + name-of-script is found more then once in it. Seems doable - but I wonder if there is no more streightforward solution ?

Greetz
 
When a script runs it does not run as the name of the script. Every script runs as wscript.exe in taskmanager.
 
A file or registry entry could be created when the script runs & destroyed when the script ends. But before acutally creating the file or entry, the script would check for the presence of the file/reg. entry. If it is there, the script must already be running.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top