2013-01-17 1 views
0

저는 스크립팅의 초보자이므로 다른 스크립트를 조정하기 시작했습니다. 명령 줄에서 Microsoft 업데이트를 확인, 다운로드 및 설치하는 스크립트를 발견했습니다. 완료되면 재부팅 명령을 포함하는 방법이 있습니까? 아니면 명령 뒤에 데이지 체인이나 파이프를 사용합니까?Microsoft Update 스크립트에서 Reboot 명령을 삽입하십시오.

그것을 실행하려면 cscript.exe를 ForceAU.vbs

/후 그것을 명령 (종료/r)을 추가 할 수있는 방법이 있나요, 아니면 스크립트 자체의 설정해야 않습니다

을 입력 ?

'************************************ 
'* Force Automatic Update Script * 
'* Goto http://www.intelliadmin.com * 
'* for more tools and utilities  * 
'************************************ 
' This script was adapted to only 
' install non-prompting updates 
' and not ask any questions 
' Original script can be found here: 
' http://msdn.microsoft.com/en-us/library/windows/desktop/aa387102(v=vs.85).aspx 

On Error Resume Next 

function IsSecurityUpdate(Update) 
Set Categories = Update.Categories 
sName = lcase(Categories.Item(0).Name) 
'This works on all languages...the category name is always in english 
if (sName = "security updates" or sName="critical updates") then 
    IsSecurityUpdate = TRUE 
else 
    IsSecurityUpdate = FALSE 
end if 
end function 

Sub ForceUpdate() 

Set updateSession = CreateObject("Microsoft.Update.Session") 
Set updateSearcher = updateSession.CreateupdateSearcher() 

WScript.Echo "Searching for updates..." & vbCRLF 

Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software' and  IsHidden=0") 

WScript.Echo vbCRLF & "Creating collection of updates to download:" 

Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl") 

bFound = FALSE 

For I = 0 to searchResult.Updates.Count-1 
    Set update = searchResult.Updates.Item(I) 
    If IsSecurityUpdate(update) then 
    WScript.Echo " " & update.Title 
    updatesToDownload.Add(update) 
    bFound = TRUE 
    end if 
Next 

if (NOT(bFound)) then 
WScript.Echo "This computer is up to date" 
Exit Sub 
end if 

WScript.Echo vbCRLF & "Downloading updates..." 

Set downloader = updateSession.CreateUpdateDownloader() 
downloader.Updates = updatesToDownload 
downloader.Download() 

WScript.Echo vbCRLF & "List of downloaded updates:" 

For I = 0 To searchResult.Updates.Count-1 
    Set update = searchResult.Updates.Item(I) 
    If update.IsDownloaded Then 
     WScript.Echo I + 1 & "> " & update.Title 
    End If 
Next 

Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl") 

WScript.Echo vbCRLF & _ 
"Creating collection of downloaded updates to install:" 

For I = 0 To searchResult.Updates.Count-1 
    set update = searchResult.Updates.Item(I) 
    If update.IsDownloaded = true Then 
    if (IsSecurityUpdate(update)) then 
     WScript.Echo I + 1 & "> adding: " & update.Title 
     updatesToInstall.Add(update) 
    end if 
    End If 
ext 


WScript.Echo "Installing updates..." 
Set installer = updateSession.CreateUpdateInstaller() 
installer.Updates = updatesToInstall 
Set installationResult = installer.Install() 

'Output results of install 
WScript.Echo "Installation Result: " & _ 
installationResult.ResultCode 
WScript.Echo "Reboot Required: " & _ 
installationResult.RebootRequired & vbCRLF 
WScript.Echo "Listing of updates installed " & _ 
"and individual installation results:" 

For I = 0 to updatesToInstall.Count - 1 
    WScript.Echo I + 1 & "> " & _ 
    updatesToInstall.Item(i).Title & _ 
    ": " & installationResult.GetUpdateResult(i).ResultCode   
Next 

end sub 

ForceUpdate() 

if (Err.Number<>0) then 
WScript.Echo "Error Downloading Updates. Check your internet connection" 
end if 

답변

1

"shutdown -r -t 5"를 실행하면 5 초 후에 재부팅됩니다.

아마 이런 식으로 뭔가 :

Set oShell = WScript.CreateObject("WSCript.shell") 

oShell.run "cmd shutdown -r -t 5" 
+0

를보다 효율적으로 사용하는 '% COMSPEC %/c' 대신 cmd''의. –

관련 문제