forked from onlycrab/Winupdates_vbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzbx.winupdate.vbs
123 lines (117 loc) · 5.19 KB
/
zbx.winupdate.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
On Error Resume Next
'----------ZABBIX PATH-----------
If WScript.Arguments.Count < 2 Then 'the path may contain spaces
senderPath = "c:\zabbix\zabbix_sender.exe"
confPath = "c:\zabbix\zabbix_agentd.win.conf"
Elseif WScript.Arguments.Count = 2 Then
senderPath = WScript.Arguments(0)
confPath = WScript.Arguments(1)
Else
WScript.Quit(1)
End If
'----------DEFINITION------------
IsSendDataWhenErrors = False
Dim WshShell, updateSession, updateSearcher, searchResult, commandPart, AllUpdates, CriticalUpdates, DefinitionUpdates, SecurityUpdates, ServicePacks, UpdateRollUps, RebootRequired, RebootRequiredForNewUpdates
Set WshShell = WScript.CreateObject("WScript.Shell")
Set updateSession = createObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
commandPart = chr(34) & senderPath & chr(34) & " -c " & chr(34) & confPath & chr(34) & " -k "
'----------SEARCH ALL------------
Set searchResult = updateSearcher.Search("Type='Software' AND IsInstalled=0") 'AllUpdates
AllUpdates = -1
AllUpdates = searchResult.Updates.count
updatesDetectedByTypes = 0
'----------SEARCH CRITICAL-------
CriticalUpdates = -1
If updatesDetectedByTypes <> AllUpdates Then
CriticalUpdates = CheckUpdatesQuantity("Software", "E6CF1350-C01B-414D-A61F-263D14D133B4") 'CriticalUpdates
updatesDetectedByTypes = updatesDetectedByTypes + CriticalUpdates
Elseif AllUpdates <> -1 Then
CriticalUpdates = 0
End If
'----------SEARCH SECURITY-------
SecurityUpdates = -1
If updatesDetectedByTypes <> AllUpdates Then
SecurityUpdates = CheckUpdatesQuantity("Software", "0FA1201D-4330-4FA8-8AE9-B877473B6441") 'SecurityUpdates
updatesDetectedByTypes = updatesDetectedByTypes + SecurityUpdates
Elseif AllUpdates <> -1 Then
SecurityUpdates = 0
End If
'----------SEARCH DEFINITION-----
DefinitionUpdates = -1
If updatesDetectedByTypes <> AllUpdates Then
DefinitionUpdates = CheckUpdatesQuantity("Software", "E0789628-CE08-4437-BE74-2495B842F43B") 'DefinitionUpdates
updatesDetectedByTypes = updatesDetectedByTypes + DefinitionUpdates
Elseif AllUpdates <> -1 Then
DefinitionUpdates = 0
End If
'----------SEARCH SERVICEPACKS---
ServicePacks = -1
If updatesDetectedByTypes <> AllUpdates Then
ServicePacks = CheckUpdatesQuantity("Software", "68C5B0A3-D1A6-4553-AE49-01D3A7827828") 'ServicePacks
updatesDetectedByTypes = updatesDetectedByTypes + ServicePacks
Elseif AllUpdates <> -1 Then
ServicePacks = 0
End If
'----------SEARCH ROOLUPS--------
UpdateRollUps = -1
If updatesDetectedByTypes <> AllUpdates Then
UpdateRollUps = CheckUpdatesQuantity("Software", "28BC880E-0592-4CBF-8F95-C79B17911D5F") 'UpdateRollUps
updatesDetectedByTypes = updatesDetectedByTypes + UpdateRollUps
Elseif AllUpdates <> -1 Then
UpdateRollUps = 0
End If
'----------REBOOT REQUIRED-------
RebootRequiredFlag = 0
errText = Err.Description
RebootRequired = ""
RebootRequired = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired\")
If Err.Description = errText Then RebootRequiredFlag = RebootRequiredFlag + 1
errText = Err.Description
RebootRequired = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending\")
If Err.Description = errText Then RebootRequiredFlag = RebootRequiredFlag + 1
If RebootRequiredFlag > 0 Then
RebootRequired = "1"
Else
RebootRequired = "0"
End If
'----------SEND DATA-------------
If AllUpdates = -1 Or CriticalUpdates = -1 Or DefinitionUpdates = -1 Or SecurityUpdates = -1 Or ServicePacks = -1 Or UpdateRollUps = - 1 Then
strRun = commandPart & "zbx.winupdate.vbs.wsusavailability -o 0"
WshShell.Run strRun,1,True
If IsSendDataThanErrors = False Then
WScript.Quit(1)
End If
Else
strRun = commandPart & "zbx.winupdate.vbs.wsusavailability -o 1"
WshShell.Run strRun,1,True
End If
strRun = commandPart & "zbx.winupdate.vbs.all -o " & CStr(AllUpdates)
WshShell.Run strRun,1,True
strRun = commandPart & "zbx.winupdate.vbs.critical -o " & CStr(CriticalUpdates)
WshShell.Run strRun,1,True
strRun = commandPart & "zbx.winupdate.vbs.definition -o " & CStr(DefinitionUpdates)
WshShell.Run strRun,1,True
strRun = commandPart & "zbx.winupdate.vbs.security -o " & CStr(SecurityUpdates)
WshShell.Run strRun,1,True
strRun = commandPart & "zbx.winupdate.vbs.servicepacks -o " & CStr(ServicePacks)
WshShell.Run strRun,1,True
strRun = commandPart & "zbx.winupdate.vbs.updaterollups -o " & CStr(UpdateRollUps)
WshShell.Run strRun,1,True
strRun = commandPart & "zbx.winupdate.vbs.datetime -o " & chr(34) & CStr(Date) & " " & CStr(Time) & chr(34)
WshShell.Run strRun,1,True
strRun = commandPart & "zbx.winupdate.vbs.rebootrequired -o " & CStr(RebootRequired)
WshShell.Run strRun,1,True
Set WshShell = Nothing
Set updateSession = Nothing
Set updateSearcher = Nothing
Set searchResult = Nothing
If Len(Err.Description) > 1 Then
WScript.Quit(1)
Else
WScript.Quit(0)
End If
Function CheckUpdatesQuantity(updateType, updateCategoryID)
Set searchResult = updateSearcher.Search("Type='" & updateType & "' AND IsInstalled=0 AND CategoryIDs contains '" & updateCategoryID & "'")
CheckUpdatesQuantity = searchResult.Updates.count
End Function