Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

Solved: Batch file closing if the same one is running


(!)

tehdansorz's Avatar
tehdansorz tehdansorz is offline
Computer Specs
Member with 59 posts.
THREAD STARTER
 
Join Date: Feb 2011
Location: Lithuania
Experience: Intermediate
03-May-2012, 09:47 AM #1
Exclamation Solved: Batch file closing if the same one is running
Hey , i really need help with this - how to make a batch file close itself if the same one is already running ? I need this so my users don't open the same program multiple times . If you want to check what i'm doing PM me or ask me here .
Squashman's Avatar
Trusted Advisor with 19,648 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
03-May-2012, 10:50 AM #2
What you would want to do at the top of your batch file is use the TASKLIST program to find cmd.exe with the window title of your batch file. IF it finds it then exit your batch file.
Then after that set the Title of your batch file

So do something like this at the top of your batch file

Code:
for /F "tokens=1" %%G in ('tasklist /V /NH /FO TABLE /FI "WINDOWTITLE eq BATCH1"') do IF %%G==cmd.exe exit /b
TITLE BATCH1
First time it runs it will not find BATCH1
Second time it runs it should exit the batch file.
tehdansorz's Avatar
tehdansorz tehdansorz is offline
Computer Specs
Member with 59 posts.
THREAD STARTER
 
Join Date: Feb 2011
Location: Lithuania
Experience: Intermediate
10-May-2012, 08:30 AM #3
Thanks ! Just the answer i needed
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


Tags
batch, close, fast, need help

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑