私はスクリプト作成の完全な初心者なので、他のスクリプトを微調整することから始めます。コマンド ラインから Microsoft の更新プログラムをチェック、ダウンロード、およびインストールするスクリプトを見つけました。完了時に再起動コマンドを含める方法、またはコマンドの後にデイジーチェーンまたはパイプを含める方法はありますか?
実行するには、cscript.exe ForceAU.vbs と入力します。
コマンド (shutdown /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