cmd使用管理员权限运行,启动路径不是当前目录


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"

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM