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

  • Home
  • SEARCH
  • 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 91353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:01:00+00:00 2026-05-10T23:01:00+00:00

Assuming Windows, is there a way I can detect from within a batch file

  • 0

Assuming Windows, is there a way I can detect from within a batch file if it was launched from an open command prompt or by double-clicking? I’d like to add a pause to the end of the batch process if and only if it was double clicked, so that the window doesn’t just disappear along with any useful output it may have produced.

Any clever ways to do this? I’m looking for solutions I could rely on to work on a machine that was configured more or less with default settings.

  • 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. 2026-05-10T23:01:00+00:00Added an answer on May 10, 2026 at 11:01 pm

    I just ran a quick test and noticed the following, which may help you:

    • When run from an open command prompt, the %0 variable does not have double quotes around the path. If the script resides in the current directory, the path isn’t even given, just the batch file name.
    • When run from explorer, the %0 variable is always enclosed in double quotes and includes the full path to the batch file.

    This script will not pause if run from the command console, but will if double-clicked in Explorer:

    @echo off setlocal enableextensions  set SCRIPT=%0 set DQUOTE='  @echo do something...  @echo %SCRIPT:~0,1% | findstr /l %DQUOTE% > NUL if %ERRORLEVEL% EQU 0 set PAUSE_ON_CLOSE=1  :EXIT if defined PAUSE_ON_CLOSE pause 

    EDIT: There was also some weird behavior when running from Explorer that I can’t explain. Originally, rather than

    @echo %SCRIPT:~0,1% | findstr /l %DQUOTE% > NUL if %ERRORLEVEL% EQU 0 set PAUSE_ON_CLOSE=1 

    I tried using just an if:

    if %SCRIPT:0,1% == ^' set PAUSE_ON_CLOSE=1 

    This would work when running from an open command prompt, but when run from Explorer it would complain that the if statement wasn’t correct.

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

Sidebar

Ask A Question

Stats

  • Questions 286k
  • Answers 286k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"]… May 13, 2026 at 4:57 pm
  • Editorial Team
    Editorial Team added an answer use aliases and double-join the user table with the friends… May 13, 2026 at 4:57 pm
  • Editorial Team
    Editorial Team added an answer Now with Theme support (include Windows, UxTheme, Themes units)! type… May 13, 2026 at 4:57 pm

Related Questions

Up to now I been using the pda emulator in visual studios 2008 (I
This will be a Windows Forms application deployed through ClickOnce. The plan is to
On Linux (or Solaris) is there a better way than hand parsing /proc/self/maps repeatedly
I'm looking into extending some code that handles automatic opening and reading of Excel

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.