Vbscript 更新安装错误

Vbscript 更新安装错误,vbscript,Vbscript,谢谢你的来访 我有一个windows更新脚本(Vbscript),用于查找、下载和安装计算机的可用更新。但是我现在正在记录这个过程,我被卡住了。。因为我不知道该怎么做: 因为我有一个小代码: f、 WriteLine UpdateInstall.Item(i).Title(在日志中显示更新的标题) 然后我想知道它是否已安装,我们可以使用IsInstalled,但如何使用它?如果我这样使用它,它会在日志中显示“false”: f、 已安装WriteLine UpdateInstall.Item(i

谢谢你的来访

我有一个windows更新脚本(Vbscript),用于查找、下载和安装计算机的可用更新。但是我现在正在记录这个过程,我被卡住了。。因为我不知道该怎么做:

因为我有一个小代码:

f、 WriteLine UpdateInstall.Item(i).Title(在日志中显示更新的标题)

然后我想知道它是否已安装,我们可以使用IsInstalled,但如何使用它?如果我这样使用它,它会在日志中显示“false”:

f、 已安装WriteLine UpdateInstall.Item(i)

对不起,我的英语不好,我希望你们能理解我的意思

IsInstalled函数的源代码:

问候

编辑(添加脚本):

选项显式
Dim fso、f、ssDefault、ssManagedServer、ssWindowsUpdate、ssOthers、更新
Dim Strc计算机、intSearchStartChar、更新会话、更新搜索器
Dim searchResult,I,update,updatesToDownload,addThisUpdate,downloader,updatesToInstall,可能需要重新启动,installer,installationResult,objWMIService,colOS,objOS
设置fso=WScript.CreateObject(“Scripting.Filesystemobject”)
设置f=fso.OpenTextFile(“C:\output.txt”,2)
'脚本结束
'服务器选择值
ssDefault=0
ssManagedServer=1
ssWindowsUpdate=2
ssOthers=3
strComputer=“.”本地计算机
'仪器值
intSearchStartChar=1
暗条纹
Set updateSession=CreateObject(“Microsoft.Update.Session”)
Set updatesarcher=updateSession.createUpdatesarcher()
updatesarcher.ServerSelection=ssWindowsUpdate
设置searchResult=updatesarcher.Search(“IsInstalled=0,类型='Software'))
f、 写线“
对于I=0的searchResult.Updates.Count-1
Set update=searchResult.Updates.Item(I)
f、 写线“
f、 WriteLine vbCRLF&&update.Title&&
f、 WriteLine“”&update.MsrcSeverity&“
f、 WriteLine“”&update.IsHidden&“
f、 WriteLine“”&update.Description&“”
f、 写入线vbCRLF&“
下一个
如果searchResult.Updates.Count=0,则
f、 写“Geen更新beschikbaar”
f、 写线“
WScript.Quit
如果结束
f、 写入线vbCRLF&“
f、 写入线vbCRLF&“
Set updatesToDownload=CreateObject(“Microsoft.Update.UpdateColl”)
对于I=0的searchResult.Updates.Count-1
Set update=searchResult.Updates.Item(I)
addThisUpdate=false
如果update.InstallationBehavior.CanRequestUserInput=true,则
f、 WriteLine I+1&“>跳过:&update.Title&”_
“因为它需要用户输入”
其他的
如果update.EulaAccepted=false,则
f、 WriteLine I+1&“>注意:”&更新.标题&_
“具有必须接受的许可协议:”
update.AcceptEula()
addThisUpdate=true
其他的
addThisUpdate=true
如果结束
如果结束
如果addThisUpdate=true,则
f、 写线“
f、 WriteLine“”&update.Title&“”
f、 WriteLine“”&update.DownloadPriority&“
f、 WriteLine“”&update.isdownload&“”
f、 WriteLine“”&update.MaxDownloadSize&“
f、 WriteLine“”&update.MinDownloadSize&“
f、 写入线vbCRLF&“
updatesToDownload.Add(更新)
如果结束
下一个
如果updatesToDownload.Count=0,则
f、 WriteLine“已跳过所有适用的更新。”
WScript.Quit
如果结束
Set downloader=updateSession.CreateUpdateDownloader()
downloader.Updates=updatesToDownload
downloader.Download()
Set updatesToInstall=CreateObject(“Microsoft.Update.UpdateColl”)
rebootMayBeRequired=错误
对于I=0的searchResult.Updates.Count-1
set update=searchResult.Updates.Item(I)
如果update.isdownload=true,则
updatesToInstall.Add(更新)
如果update.InstallationBehavior.RebootBehavior>0,则
RebootMayberrequired=true
如果结束
如果结束
下一个
如果updatesToInstall.Count=0,则
f、 WriteLine“未成功下载任何更新。”
WScript.Quit
如果结束
如果rebootMayBeRequired=true,则
如果结束
f、 写入线vbCRLF&“
f、 写入线vbCRLF&“
Set installer=updateSession.CreateUpdateInstaller()
installer.Updates=updatesToInstall
Set installationResult=installer.Install()
f、 写入线vbCRLF&“
对于I=0的UpdatesInstall.Count-1
f、 WriteLine UpdatesInstall.Item(i).标题
f、 WriteLine UpdateInstall.Item(i).可卸载
下一个
f、 写线“
f、 写入线vbCRLF&“
设置objWMIService=GetObject(“winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\”&_
strComputer&“\root\cimv2”)
Set colOS=objWMIService.ExecQuery(“从Win32\U操作系统中选择*)
对于巨像中的每个OBJO
objOS.reboot()
下一个
f、 接近

IsInstaller
布尔值(真/假),假表示未安装更新。你到底需要什么?将
已安装
/
未安装
写入日志,而不是
/
?根据IsInstalledValue执行一些额外的操作?还有什么吗?嗨,我只需要知道是否安装了更新是或否(假或真)。但是当我使用脚本并完成时,我会转到我的日志,然后它会说每个更新都是假的(未安装),这不是真的,因为当我转到“配置>windows更新>已安装更新”时,我会看到已安装的更新。。所以我猜我的代码出错了。你能把你的完整脚本发出来吗?它可能有助于检测问题。当然,我添加了脚本:)替换f.WriteLine UpdatesInstall.Item(i)。可使用f.WriteLine UpdatesInstall.Item(i)卸载。IsInstalled my bad。。。
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