0
我是一個完全的腳本編程新手,所以剛開始時只是試圖調整其他腳本。我發現了一個腳本,用於檢查,下載並從命令行安裝Microsoft更新。有沒有辦法在完成時包含重新啓動命令,或者在後面的命令中使用菊花鏈或管道?在微軟更新腳本中插入重新啓動命令
要運行它,你鍵入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
更好地使用'%COMSPEC%/ C',而不是'cmd'。 –