2015-03-13 69 views
0
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 

回答

0

Set語句分配一個對象引用給一個變量或特性,或相關聯的過程參考與事件。這不是你的情況,因爲你要求ComputerName屬性WshNetwork對象。因此,而不是set Computer = WshNetwork.ComputerName,使用

Computer = WshNetwork.ComputerName 
+0

Josefz嗨,我已經修改,並用管理員權限運行腳本,得到許可被拒絕的錯誤, – Prakaash2109 2015-03-16 05:41:44