为什么以管理员身份运行时批处理脚本无法执行? [英] Why does my batch script fail to execute when run as administrator?

查看:74
本文介绍了为什么以管理员身份运行时批处理脚本无法执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建Windows批处理脚本,该脚本将允许我为Windows 7 64位部署准备更新,但脚本无法正常启动.我将所有文件都放在同一个文件夹中,我尝试解压缩文件,然后在正常启动文件解压缩时通过dism安装它们,但dism无法正确启动,当我以管理员身份运行时,文件将不会解压缩并dism退出并显示代码2.我在做什么错了?

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

推荐答案

'以管理员身份运行会更改当前目录!添加这些行以向自己证明.下面的第二行将为您恢复它.稍后删除ECHO语句.

'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%

也请在末尾添加此行:

popd

这篇关于为什么以管理员身份运行时批处理脚本无法执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆