Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:32:00+00:00 2026-05-24T08:32:00+00:00

Say I have a batch file for carrying out a long build and at

  • 0

Say I have a batch file for carrying out a long build and at the end it creates an EXE. If I forget to close the app down before I start the build, the link phase fails when it can’t re-create the EXE.

I want to check if the EXE is open at the start of the build. I tried renaming the EXE file to itself but although this gives an access denied error the rename command (being an internal command) doesn’t set %ErrorLevel%.

What’s a non-destructive way of checking for an open file that sets %ErrorLevel% to a non-zero value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:32:01+00:00Added an answer on May 24, 2026 at 8:32 am

    The rename method didn’t work for me (tested on Windows XP SP3). I started an arbitrary application and tried to rename it to itself. There was no error, no effect whatsoever.

    However, this method did work:

    COPY /B app.exe+NUL app.exe
    

    When the application was running, this command produced me an error message. And when the application was unengaged, not only this command preserved the contents of file, but it also left the modification timestamp unchanged.

    If I were you, therefore, I would probably use this command (at the beginning of the batch script, like you said) in this way:

    COPY /B app.exe+NUL app.exe >NUL || (GOTO :EOF)
    

    The || operator passes the control to the command/block next to it if the previous command has failed (raised the errorlevel value). Therefore, the above command would terminate the script if COPY failed (which it would if the file was open).

    The error message would be preserved (because such messages are usually sent to the so called standard error device and are not discarded with the >NUL redirection, while other, non-error messages are typically sent to the standard output and so can be suppressed with >NUL) and serve as an explanation of the premature termination of the script. However, if you want to display your own message instead, you can try something like this:

    COPY /B app.exe+NUL app.exe >NUL 2>NUL || (ECHO Target file inaccessible& GOTO :EOF)
    

    While >NUL hides whatever is sent to the standard output, 2>NUL does the same for the standard error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, let's say that I have a batch file that calls myapp1.exe and myapp1.exe
Let's say I have a batch file that has padding in it, and I
Say I have a batch file where in I call a VBScript(which returns the
This is a very specific question, however; Say I have a batch file running
I have a batch file with an external configuration file. Say I needed to
In my Windows batch file I have a various amount of variables. Lets say
Let say ,I have a batch file and I have three commands like: Execute
Say I have a batch file C:\myscript.bat , how can I add a toolbar
I have a batch file and I want to include an external file containing
Say I've got a windows batch file with a file extension .batscript , and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.