https://stackoverflow.com/questions/672693/windows-batch-file-starting-directory-when-run-as-admin
Better than
cd
is
pushd
which will
- change drive letter if starting from
D:\...
- assign a drive letter if on a UNC network path
So
pushd %~dp0
is good.
Good practice is then to call
popd
when done.
https://ss64.com/nt/pushd.html
Run as Admin
When a batch script is 'Run as Admin', the current directory will be set to C:\windows\system32\.
Using the following pushd command at the start of the script will restore the normal current directory.
This works by setting the current directory to the location of the batch script, using the %0 parameter
pushd "%~dp0"
转载于:https://www.cnblogs.com/chucklu/p/10557363.html