感谢您的光临。
我有一个Windows更新脚本(Vbscript),可以查找,下载和安装我的计算机的可用更新。但我现在正在记录这个过程,我被卡住了......因为我无法弄清楚该怎么做:
因为我有一些代码:
f.WriteLine updatesToInstall.Item(i).Title(显示日志中更新的标题)
然后我想知道它是否已安装,为此我们可以使用IsInstalled,但如何使用它?如果我像这样使用它,它会在日志中给我'假':
f.WriteLine updatesToInstall.Item(i).IsInstalled
抱歉我的英文不好,我希望你们能理解我的意思。
IsInstalled函数的来源:http://msdn.microsoft.com/en-us/library/windows/desktop/aa386896(v=vs.85).aspx
亲切的问候
编辑(添加脚本):
option explicit
Dim fso, f, ssDefault, ssManagedServer, ssWindowsUpdate, ssOthers, updates
Dim strComputer, intSearchStartChar, updateSession, updateSearcher
Dim searchResult, I, update, updatesToDownload, addThisUpdate, downloader, updatesToInstall, rebootMayBeRequired, installer, installationResult, objWMIService, colOS, objOS
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set f = fso.OpenTextFile("C:\output.txt", 2)
'End of Script
'ServerSelection values
ssDefault = 0
ssManagedServer = 1
ssWindowsUpdate = 2
ssOthers = 3
strComputer = "." ' Local Computer
'InStr values
intSearchStartChar = 1
dim strTitle
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
updateSearcher.ServerSelection = ssWindowsUpdate
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
f.WriteLine "<Gevonden updates>"
For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
f.WriteLine "<Update info>"
f.WriteLine vbCRLF & "<titel>" & update.Title & "</titel>"
f.WriteLine "<status>" & update.MsrcSeverity & "</status>"
f.WriteLine "<verborgen>" & update.IsHidden & "</verborgen>"
f.WriteLine "<omschrijving>" & update.Description & "</omschrijving>"
f.WriteLine vbCRLF & "</Update info>"
Next
If searchResult.Updates.Count = 0 Then
f.WriteLine "<Error> Geen updates beschikbaar </Error>"
f.WriteLine "</Updates>"
WScript.Quit
End If
f.WriteLine vbCRLF & "</Gevonden updates>"
f.WriteLine vbCRLF & "<Gedownloadde updates>"
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
addThisUpdate = false
If update.InstallationBehavior.CanRequestUserInput = true Then
f.WriteLine I + 1 & "> skipping: " & update.Title & _
" because it requires user input"
Else
If update.EulaAccepted = false Then
f.WriteLine I + 1 & "> note: " & update.Title & _
" has a license agreement that must be accepted:"
update.AcceptEula()
addThisUpdate = true
Else
addThisUpdate = true
End If
End If
If addThisUpdate = true Then
f.WriteLine "<Download info>"
f.WriteLine "<titel>" & update.Title & "</titel>"
f.WriteLine "<downloadpriority>" & update.DownloadPriority & "</downloadproirity>"
f.WriteLine "<isdownloaded>" & update.IsDownloaded & "</isdownloaded>"
f.WriteLine "<maxdownloadsize>" & update.MaxDownloadSize & "</maxdownloadsize>"
f.WriteLine "<mindownloadsize>" & update.MinDownloadSize & "</mindownloadsize>"
f.WriteLine vbCRLF & "</Download info>"
updatesToDownload.Add(update)
End If
Next
If updatesToDownload.Count = 0 Then
f.WriteLine "All applicable updates were skipped."
WScript.Quit
End If
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
rebootMayBeRequired = false
For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
updatesToInstall.Add(update)
If update.InstallationBehavior.RebootBehavior > 0 Then
rebootMayBeRequired = true
End If
End If
Next
If updatesToInstall.Count = 0 Then
f.WriteLine "<Error>No updates were successfully downloaded.</Error>"
WScript.Quit
End If
If rebootMayBeRequired = true Then
End If
f.WriteLine vbCRLF & "</Gedownloadde updates>"
f.WriteLine vbCRLF & "<Installatie>"
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
f.WriteLine vbCRLF & "<Geinstalleerde updates>"
For I = 0 to updatesToInstall.Count - 1
f.WriteLine updatesToInstall.Item(i).Title
f.WriteLine updatesToInstall.Item(i).IsUninstallable
Next
f.WriteLine "</Geinstalleerde updates>"
f.WriteLine vbCRLF & "</Installatie>"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOS
objOS.Rebooot()
Next
f.Close