Why does my batch script fail to execute when run as administrator?

折月煮酒 提交于 2020-01-07 06:26:29

问题


I am trying to create a windows batch script that will allow me to deploy preparation updates for Windows 7 64 bit but the script will not launch properly. I have all of the files inside of the same folder and I am attempting to extract the files then install them through dism when I launch it normally the files extract but dism does not launch correctly, when I run as administrator the files will not extract and dism exits with code 2. What am I doing wrong?

expand -F:* .\Windows6.1-KB3135445-x64.msu .\ 
timeout 2
DISM.exe /online /Add-Package /PackagePath:.\Windows6.1-KB3135445-x64.cab 
expand -F:* .\Windows6.1-KB3050265-x64.msu .\ 
timeout 2
DISM.exe /online /Add-Package /PackagePath:.\Windows6.1-KB3050265-x64.cab 
expand -F:* .\Windows6.1-KB3065987-v2-x64.msu .\ 
timeout 2
DISM.exe /online /Add-Package /PackagePath:.\Windows6.1-KB3065987-v2-x64.cab 
expand -F:* .\Windows6.1-KB3102810-x64.msu .\ 
timeout 2
DISM.exe /online /Add-Package /PackagePath:.\Windows6.1-KB3102810-x64.cab 
expand -F:* .\Windows6.1-KB3138612-x64.msu .\ 
timeout 2
DISM.exe /online /Add-Package /PackagePath:.\Windows6.1-KB3138612-x64.cab 
expand -F:* .\Windows6.1-KB3161608-x64.msu .\ 
timeout 2
DISM.exe /online /Add-Package /PackagePath:.\Windows6.1-KB3161608-x64.cab 
expand -F:* .\Windows6.1-KB3161664-x64.msu .\ 
timeout 2
DISM.exe /online /Add-Package /PackagePath:.\Windows6.1-KB3161664-x64.cab 
pause

回答1:


'Run as administrator changes the current directory! Add these lines to prove it to yourself. Second line below will restore it for you. Delete the ECHO statements later.

echo %cd%
pushd %~dp0
echo %cd%

Also add this line at end:

popd


来源:https://stackoverflow.com/questions/38378107/why-does-my-batch-script-fail-to-execute-when-run-as-administrator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!