Computing.Net > Forums > Programming > Batch Check File is Opened

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Check File is Opened

Reply to Message Icon

Name: davi albuquerque
Date: November 25, 2008 at 10:13:09 Pacific
OS: Windows XP
CPU/Ram: q6600/4gb
Product: PC
Comment:

Hi,

I have a "software.bat" on windows xp, but sometimes users open 2 times and system stay slow. how i check if file is opened?

thanks!
Davi Albuquerque



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: November 26, 2008 at 04:43:50 Pacific
Reply:

Here's my suggestion. Perhaps someone else can come up with a better idea.

My technique assumes that this batch file will run under its own window (e.g. by double-clicking the file in Windows Explorer) and will have a unique window title, except if another instance of the same file is already running.

When the batch file stops running, you must ensure the window is closed, to allow other instances of the batch file to run.

title %~nx0
setlocal
set /a numProcs = 0
for /f %%a in ('tasklist /nh /fi "windowtitle eq %~nx0"') do (
set /a numProcs += 1
)
if not %numProcs% == 1 (
echo Another instance of this batch file is already running.
exit /b 1
)


0

Response Number 2
Name: davi albuquerque
Date: November 27, 2008 at 06:29:54 Pacific
Reply:

WoW! Perfect! You are Great Man!

Thank You
Davi


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch Check File is Opened

How to check if a file is opened www.computing.net/answers/programming/how-to-check-if-a-file-is-opened/6494.html

Batch file to check file attribute www.computing.net/answers/programming/batch-file-to-check-file-attribute-/16175.html

Batch File that opens network drive www.computing.net/answers/programming/batch-file-that-opens-network-drive/11683.html