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.
views:
1196answers:
3Fantastic, I didn't know this one.Thanks a lot
Marc
2009-03-23 10:43:48
A:
I use:
cd %0..
at the beginning of the batch file to change directory to the directory where the batch file was started in.
-Mathew
Mathew
2009-06-01 18:55:33
This wont work because %0 contains the file name of the batch file not its directory.
Martin
2009-06-30 07:04:31
A:
A working solution here:
http://www.vistax64.com/vista-general/79849-run-administrator-changes-default-directory.html
FOR /F %%I IN ("%0") DO SET BATDIR=%%~dpI
ECHO The batch file is located in directory %BATDIR%
domotor
2010-10-25 12:29:59