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 ".\"?