问题
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