简体   繁体   中英

Why working directory changes to system32 when executing a batch file that's in a different directory and how to change it

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?

Put this line at the top of your bat file:

pushd %~dp0

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM