繁体   English   中英

计算机重启后恢复批处理脚本

[英]Resume batch script after computer restart

我有一堆运行 Windows 2000 Pro 和 IE 5.0 的旧机器,我想用 Silverlight 升级到 IE 6。我从微软的 web 站点下载了 IE6 和 Silverlight 安装程序,幸运的是它们都有命令行选项允许它们在“静音模式”。

我将这两个命令放在 DOS 批处理脚本中并运行它,但 IE6 安装程序需要自动重启计算机,所以问题是如何恢复脚本并运行第二个命令(安装 Silverlight)。

我的批处理文件现在非常简单:

ie6setup.exe /Q
silverlight.exe /q

据我所知,批处理文件在重新启动计算机后无法恢复执行。 有没有办法让他们这样做? 有没有另一种方法来完成我需要的。

谢谢

基于Tim的帖子,在测试时,将“two”附加到批处理文件中导致无法找到批处理标签“onetwo”,因此修改为从单独的文本文件中读取和写入“当前”变量,留下批处理档案未触及;

@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
)

您可以将第二个命令放在一个独占的批处理文件中,并在Windows启动时自动添加一个条目到regedit来执行这个批处理文件,这样就可以在计算机重启后执行Silverlight

你听说过msconfig吗? 在某些系统上,您正在寻找的regedit PATH是:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

但你可能想检查一下。 如果要创建批处理文件以在注册表上写入该密钥,您可能应该查看本教程

如果使用命令ie6setup.exe /q /r:n进行IE6安装,则它将不会自动重启(有关详细信息,请参阅此页面 )。 然后理论上你可以立即安装SilverLight,然后重新启动; 但由于需要重新启动,SL安装有可能会拒绝,但尝试它不会有什么坏处...

我知道它有点旧,但这很有效:

@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
@echo off

set "_RunOnce=HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"

rem./ :: if no argument was passed, this line will be ignored, but if so, it will be executed here == ^> & %~1

:1st_command
ie6Setup.exe /Q
shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :2nd_command\"" /f & goto :eof 

:2nd_command
SilverLight.exe /Q
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :3rd_command\"" /f & goto :eof 

:3rd_command
Skype-8.92.0.401.exe /VerySilent /NoRestart /SuppressMsgBoxes /DL=1 & goto :eof

可以在不创建或操作其他文件中的读数的情况下执行此操作,只需写入和读取密钥并使用执行中传递的 arguments 来控制相关执行所需的命令,使用goto command作为参数%1


@echo off

set "_RunOnce=HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"

rem./ if no argument was passed, below will be ignored, but if so, it will be executed here == ^> & %~1

:1st_command
mode con cols=50 lines=1 | title starting %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "stackoverflow.com" /new-tab
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :2nd_command\"" /f & goto :eof 

:2nd_command
mode con cols=50 lines=1 | title starting %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "meta.stackexchange.com" /new-tab
timeout -1 | shutdown -r -t 0 | reg add "%_RunOnce%" /v "%~n0" /d "\"%~f0\" \"goto :3rd_command\"" /f & goto :eof 

:3rd_command
mode con cols=50 lines=1 | title %~1
start "google" /wait "c:\program files (x86)\Google\Chrome\Application\chrome.exe" "www.amazon.com" /new-tab
goto :eof 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM