簡體   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