Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for disablesilverlightupdates.vbs

(view source code of disablesilverlightupdates.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim blnFoundOne
  4. Dim i, intCount
  5. Dim objSearchResult, objWUpdate, objWUSearcher, objWUSession
  6.  
  7. If WScript.Arguments.Count > 0 Then Syntax
  8.  
  9. Set objWUSession  = CreateObject( "Microsoft.Update.Session" )
  10. Set objWUSearcher = objWUSession.CreateUpdateSearcher( )
  11. objWUSearcher.Online = False
  12.  
  13. blnFoundOne = True
  14. intCount    = 0
  15. While blnFoundOne
  16. 	WScript.Echo( "Searching..." )
  17. 	blnFoundOne = False
  18. 	Set objSearchResult = objWUSearcher.Search( "IsHidden=0 And IsInstalled=0" )
  19. 	For i = 0 To objSearchResult.Updates.Count - 1
  20. 		Set objWUpdate = objSearchResult.Updates.Item(i)
  21. 		If InStr( objWUpdate.Title, "Microsoft Silverlight" ) > 0 Then
  22. 			WScript.Echo "Hiding " & objWUpdate.Title
  23. 			objWUpdate.IsHidden = 1
  24. 			blnFoundOne = True
  25. 			intCount    = intCount + 1
  26. 		End If
  27. 		Set objWUpdate = Nothing
  28. 	Next
  29. 	Set objSearchResult = Nothing
  30. Wend
  31.  
  32. Set objWUSearcher = Nothing
  33. Set objWUSession  = Nothing
  34.  
  35. Select Case intCount
  36. 	Case 0:
  37. 		WScript.Echo vbCrLf & "All optional Microsoft Silverlight updates were" _
  38. 		           & vbCrLf & "either installed or hidden already, no change required"
  39. 	Case 1:
  40. 		WScript.Echo vbCrLf & "Hidden 1 optional Microsoft Silverlight update"
  41. 	Case Else:
  42. 		WScript.Echo vbCrLf & "Hidden " & intCount & " optional Microsoft Silverlight updates"
  43. End Select
  44.  
  45. WScript.Quit intCount
  46.  
  47.  
  48. Sub Syntax
  49. 	Dim strMsg
  50. 	strMsg = vbCrLf _
  51. 	       & "DisableSilverlightUpdates.vbs,  version 1.00" _
  52. 	       & vbCrLf _
  53. 	       & "Hide all Silverlight updates in Windows Update" _
  54. 	       & vbCrLf & vbCrLf _
  55. 	       & "Usage:  DisableSilverlightUpdates.vbs" _
  56. 	       & vbCrLf & vbCrLf _
  57. 	       & "Notes:  If you do not wish to install Microsoft Silverlight, Windows" _
  58. 	       & vbCrLf _
  59. 	       & "        Update will nag about 16 times to install it as an optional" _
  60. 	       & vbCrLf _
  61. 	       & "        update; hiding each of these 16 optional updates manually is" _
  62. 	       & vbCrLf _
  63. 	       & "        possible, but why not let this script automate that for you?" _
  64. 	       & vbCrLf _
  65. 	       & "        This script was originally written in JScript by Tony Marques" _
  66. 	       & vbCrLf _
  67. 	       & "        (https://superuser.com/a/1009947)" _
  68. 	       & vbCrLf _
  69. 	       & "        I only ""translated"" it into VBScript and added the counter." _
  70. 	       & vbCrLf _
  71. 	       & "        This script's return code is the number of Silverlight updates" _
  72. 	       & vbCrLf _
  73. 	       & "        hidden by this script, or -1 in case of command line errors." _
  74. 	       & vbCrLf & vbCrLf _
  75. 	       & "Translated by Rob van der Woude" _
  76. 	       & vbCrLf _
  77. 	       & "http://www.robvanderwoude.com"
  78. 	WScript.Echo strMsg
  79. 	WScript.Quit -1
  80. End Sub
  81.  

page last modified: 2024-04-16; loaded in 0.0082 seconds