我得到错误“所需的对象”:[字符串:“主机名”]”
问题描述:
Dim Computer, WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
Computer = WshNetwork.ComputerName
Dim FSO, OutPutFile
Const ForWriting = 2
Const ForAppending = 8
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim EndFile, wsusscn2
EndFile = "c:\Scripts\" & Computer & ".csv" ' choose the location for the output
wsusscn2 = "c:\Scripts\wsusscn2.cab" ' choose location of the cab file
Set OutPutFile = FSO.OpenTextFile(EndFile, ForWriting, True)
Set UpdateSession = CreateObject("Microsoft.Update.Session")
Set UpdateServiceManager = CreateObject("Microsoft.Update.ServiceManager")
Set UpdateService = UpdateServiceManager.AddScanPackageService(_
"Offline Sync Service", wsusscn2)
Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()
UpdateSearcher.ServerSelection = 3 ' ssOthers
UpdateSearcher.ServiceID = UpdateService.ServiceID
Set searchResult = UpdateSearcher.Search("IsInstalled=0")
Set Updates = SearchResult.Updates
OutPutFile.WriteLine "Missing Patches " & Date & Computer
OutPutFile.WriteLine "." OutPutFile.WriteLine "."
If searchResult.Updates.Count = 0 Then
OutPutFile.WriteLine "There are no applicable updates."
WScript.Quit
End If
For I = 0 To searchResult.Updates.Count - 1
Set Update = searchResult.Updates.Item(I)
OutPutFile.WriteLine Update.Title
Next
OutPutFile.Close
WScript.Quit
答
Set
语句分配一个对象引用给一个变量或特性,或相关联的过程参考与事件。这不是你的情况,因为你要求ComputerName
属性的WshNetwork
对象。因此,而不是set Computer = WshNetwork.ComputerName
,使用
Computer = WshNetwork.ComputerName
Josefz嗨,我已经修改,并用管理员权限运行脚本,得到许可被拒绝的错误, – Prakaash2109 2015-03-16 05:41:44