windows 计算机重启后恢复批处理脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3331947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resume batch script after computer restart
提问by del.ave
I have a bunch of old machines running Windows 2000 Pro and IE 5.0 which I want to upgrade to IE 6 with Silverlight. I downloaded the IE6 and Silverlight installers from Microsoft's web sites and fortunately they both have command line options to allow them to run in "silent mode".
我有一堆运行 Windows 2000 Pro 和 IE 5.0 的旧机器,我想用 Silverlight 将它们升级到 IE 6。我从微软的网站下载了 IE6 和 Silverlight 安装程序,幸运的是它们都有命令行选项,允许它们在“静默模式”下运行。
I put the two commands in a DOS batch script and ran it, but the IE6 installer requires makes an automatic computer restart so the question is how to resume the script and run the 2nd command (install Silverlight).
我将这两个命令放在一个 DOS 批处理脚本中并运行它,但 IE6 安装程序需要自动重启计算机,所以问题是如何恢复脚本并运行第二个命令(安装 Silverlight)。
My batch file is very simple right now:
我的批处理文件现在非常简单:
ie6setup.exe /Q
silverlight.exe /q
From what I know, batch files can't resume execution after restarting the computer. Is there a way to make them do that? of is there another way to accomplish what I need.
据我所知,重新启动计算机后批处理文件无法恢复执行。有没有办法让他们这样做?有没有另一种方法来完成我所需要的。
Thank you
谢谢
回答by Valiante
Based on Tim's post which, when tested, appended "two" to the batch file resulting in a failure to find the batch label "onetwo", so amended to read & write the "current" variable from a seperate text file, leaving the batch file untouched;
基于 Tim 的帖子,在测试时,将“two”附加到批处理文件导致无法找到批处理标签“onetwo”,因此修改为从单独的文本文件读取和写入“current”变量,留下批处理文件原封不动;
@echo off
call :Resume
goto %current%
goto :eof
:one
::Add script to Run key
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /d %~dpnx0 /f
echo two >%~dp0current.txt
echo -- Section one --
pause
shutdown -r -t 0
goto :eof
:two
echo three >%~dp0current.txt
echo -- Section two --
pause
shutdown -r -t 0
goto :eof
:three
::Remove script from Run key
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v %~n0 /f
del %~dp0current.txt
echo -- Section three --
pause
goto :eof
:resume
if exist %~dp0current.txt (
set /p current=<%~dp0current.txt
) else (
set current=one
)
回答by karlphillip
You could put the second command in a exclusive batch file, and add an entry to regedit to execute this batch file automatically upon Windows' start, making silverlightbe executed after the computer restarts.
您可以将第二条命令放在一个单独的批处理文件中,并在 regedit 中添加一个条目,以便在 Windows 启动时自动执行此批处理文件,从而在计算机重新启动后执行Silverlight。
Have you heard of msconfig? On some systems the regedit PATH you are looking for is:
你听说过msconfig吗?在某些系统上,您正在寻找的 regedit PATH 是:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
But you may want to check that. If you want to make a batch file to write that key on the registry, you probably should take a look at this tutorial.
但你可能想检查一下。如果您想制作一个批处理文件以在注册表上写入该键,您可能应该查看本教程。
回答by ewall
If you do the IE6 installation with the command ie6setup.exe /q /r:n
then it won't reboot automatically (see this pagefor details). Then theoretically you could install SilverLight immediately, and then reboot afterwards; but there is a chance that the SL install will refuse due to the need of a reboot, but it won't hurt to try it...
如果您使用该命令ie6setup.exe /q /r:n
进行IE6 安装,则它不会自动重新启动(有关详细信息,请参阅此页面)。那么理论上你可以立即安装SilverLight,然后重启;但是由于需要重新启动,SL 安装有可能会拒绝,但尝试它不会有什么坏处...
回答by Tim Grey
I know its a bit old but this works amazingly:
我知道它有点旧,但这非常有效:
@echo off
call :Resume
goto %current%
goto :eof
:one
echo two >>myfile.cmd
::REBOOT HERE
goto :eof
:two
echo resumed here
goto :eof
:resume
rem THIS PART SHOULD BE AT THE BOTTOM OF THE FILE
set current=one