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 166917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:10:56+00:00 2026-05-11T12:10:56+00:00

I have a batch file which is in a directory and must be run

  • 0

I have a batch file which is in a directory and must be run from there as well because it updates files within this directory.
This works perfectly fine, except when the user runs the batch file as administrator (required on Vista). Then the starting directory is C:\Windows\System32.

Is there any way to still be able to know from which directory the batch file was run?
I dont want the user to enter the directory manually.

  • 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-11T12:10:57+00:00Added an answer on May 11, 2026 at 12:10 pm

    Try to access the batch files path like this:

    echo %~dp0 

    For more information see the following quote from the command for /? that describes how the above command works:

     You can now use the following optional syntax:      %~I         - expands %I removing any surrounding quotes (')     %~fI        - expands %I to a fully qualified path name     %~dI        - expands %I to a drive letter only     %~pI        - expands %I to a path only     %~nI        - expands %I to a file name only     %~xI        - expands %I to a file extension only     %~sI        - expanded path contains short names only     %~aI        - expands %I to file attributes of file     %~tI        - expands %I to date/time of file     %~zI        - expands %I to size of file     %~$PATH:I   - searches the directories listed in the PATH                    environment variable and expands %I to the                    fully qualified name of the first one found.                    If the environment variable name is not                    defined or the file is not found by the                    search, then this modifier expands to the                    empty string  The modifiers can be combined to get compound results:      %~dpI       - expands %I to a drive letter and path only     %~nxI       - expands %I to a file name and extension only     %~fsI       - expands %I to a full path name with short names only     %~dp$PATH:I - searches the directories listed in the PATH                    environment variable for %I and expands to the                    drive letter and path of the first one found.     %~ftzaI     - expands %I to a DIR like output line 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 173k
  • Answers 173k
  • 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 I've not used Ninject, but I would assume you need… May 12, 2026 at 2:46 pm
  • Editorial Team
    Editorial Team added an answer Did you make sure to add a reference to WindowsBase.dll?… May 12, 2026 at 2:46 pm
  • Editorial Team
    Editorial Team added an answer The destructor is called : for whatever object you have… May 12, 2026 at 2:46 pm

Related Questions

I have a directory which contains files and a number of levels of subdirectories:
Is it possible to change the Windows command prompt working directory via Python script?
I'm trying to write a small batch script that will delete files old files
I'm working on script right now which has to run each ruby script in

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.