Home > Mobile >  Why working directory changes to system32 when executing a batch file that's in a different dir
Why working directory changes to system32 when executing a batch file that's in a different dir

Time:08-17

I have a batch file that's in my desktop and it works properly when I execute it using double click. But when I execute it using a task scheduler or run as administrator, the working directory changes to C:\Windows\system32 and it doesn't work properly.

What's the reason why it happens and how do I retain the working directory?

CodePudding user response:

Put this line at the top of your bat file:

pushd %~dp0

See this post for details Difference between "%~dp0" and ".\"?

  • Related