2

My case is similar to the question (except what to mention after):
Windows batch file starting directory when 'run as admin'

Brief:

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.

Is there any way to still be able to know from which directory the batch file was run (when it's run as administrator)?
I don't want the user to enter the directory manually.

The solution mentioned that I used is:

Try to access the batch files path like this:

echo %~dp0

Now my case is as follow:
I have shortcuts for my batch file in other directories. When I run one of the shortcuts, the starting directory is that of the original batch file (not the path of the shortcut).

Is there any way to still be able to know from which directory the shortcut (of the batch file) was run?

Community
  • 1
  • 1
Omar
  • 6,681
  • 5
  • 21
  • 36

1 Answers1

0

Copy this script into each directory that has one of your shortcuts. Modify the shortcuts to call this script. Then modify your script to use %CD%.

@cd /d %~dp0
@call path\to\your\script.cmd
jwdonahue
  • 6,199
  • 2
  • 21
  • 43