windows 10 - In VBScript, I need a code to subtract 1 from searchResult.Updates.Count, so that Count = 0 and WScript.Quit will be run consequently
I already googled for hours but failed to find the answer.
'ServerSelection values
ssDefault = 0
ssManagedServer = 1
ssWindowsUpdate = 2
ssOthers = 3
'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'")
For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
If update.Title = "Intel Corporation driver update for Intel(R) HD Graphics" Then
I need a code on this line to subtract 1 from searchResult.Updates.Count, so that Count = 0 and WScript.Quit will be run consequently.
End If
If searchResult.Updates.Count = 0 Then
WScript.Quit
End If
set objShell = createobject("wscript.shell")
objShell.Run("ms-settings:windowsupdate") , 0
Next
WScript.Quit
The above VBScript checks for Windows updates. I want to remove some updates such as driver updates from searchResult.Updates.Count
, so that searchResult.Updates.Count = 0
and WScript.Quit
will be run consequently. I want it to take no action when specified updates are found and take actions only when other updates are found.
Answer
Having read duDE's above answer, I have thought up the following:
'ServerSelection values
ssDefault = 0
ssManagedServer = 1
ssWindowsUpdate = 2
ssOthers = 3
'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'")
If searchResult.Updates.Count = None Then
WScript.Quit
Else
Dim value : value = searchResult.Updates.Count
End If
For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
'The following excluded updates have to be hidden via 'Show or hide updates' beforehand.
'Otherwise, they will be downloaded and installed by Windows Update.
If update.Title = "The full update title" Then Value = Value - 1
If update.Title = "The full update title" Then Value = Value - 1
If update.Title = "The full update title" Then Value = Value - 1
An_item = "KB2267602"
Set Act=CreateObject("wscript.shell")
If instr(update.Title, An_item) <> 0 Then
Act.Run("""C:\Program Files\Windows Defender\MpCmdRun.exe"" ""-SignatureUpdate"""), 0
value = value - 1
End If
Next
If Value = 0 Then
WScript.Quit
End If
result = MsgBox (_
"The number of available updates is(" & Value & ")." & vbNewLine &_
"Do you want to open【Windows Update】?", vbYesNo + vbQuestion,_
"【There are available updates.】")
Select Case result
Case vbYes
Act.run("ms-settings:windowsupdate")
Case vbNo
WScript.Quit
End Select
It works at my end. A dialog box will appear only if there are available updates to the exclusion of unwanted ones. Please tell me whether it works at your end or can be improved.
Comments
Post a Comment