Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for disablelanguagepackupdates.vbs

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

  1. Option Explicit
  2.  
  3. Dim i, intCount, intSkipped
  4. Dim objRE, objSearchResult, objWUpdate, objWUSearcher, objWUSession
  5. Dim strException
  6.  
  7. strException = Null
  8.  
  9. With WScript.Arguments
  10. 	If .Unnamed.Count > 0 Then Syntax
  11. 	If .Named.Count   > 1 Then Syntax
  12. 	If .Named.Count   = 1 Then
  13. 		If .Named.Exists( "X" ) Then
  14. 			strException = .Named.Item( "X" )
  15. 		Else
  16. 			Syntax
  17. 		End If
  18. 	End If
  19. End With
  20.  
  21. Set objWUSession  = CreateObject( "Microsoft.Update.Session" )
  22. Set objWUSearcher = objWUSession.CreateUpdateSearcher( )
  23. objWUSearcher.Online = False
  24.  
  25. If Not IsNull( strException ) Then
  26. 	Set objRE = New RegExp
  27. 	objRE.Global     = True
  28. 	objRE.IgnoreCase = True
  29. 	objRE.Pattern    = strException
  30. End If
  31.  
  32. intCount   = 0
  33. intSkipped = 0
  34. WScript.Echo( "Searching..." )
  35. Set objSearchResult = objWUSearcher.Search( "IsHidden=0 And IsInstalled=0" )
  36. For i = 0 To objSearchResult.Updates.Count - 1
  37. 	Set objWUpdate = objSearchResult.Updates.Item(i)
  38. 	If InStr( objWUpdate.Title, "Language Pack" ) > 0 Then
  39. 		If IsNull( strException ) Then
  40. 			WScript.Echo "Hiding " & objWUpdate.Title
  41. 			objWUpdate.IsHidden = 1
  42. 			intCount = intCount + 1
  43. 		Else
  44. 			If objRE.Test( objWUpdate.Title ) Then
  45. 				WScript.Echo "Skipping " & objWUpdate.Title
  46. 				intSkipped = intSkipped + 1
  47. 			Else
  48. 				WScript.Echo "Hiding " & objWUpdate.Title
  49. 				objWUpdate.IsHidden = 1
  50. 				intCount = intCount + 1
  51. 			End If
  52. 		End If
  53. 	End If
  54. 	Set objWUpdate = Nothing
  55. Next
  56. Set objSearchResult = Nothing
  57.  
  58. If Not IsNull( strException ) Then Set objRE = Nothing
  59. Set objWUSearcher = Nothing
  60. Set objWUSession  = Nothing
  61.  
  62. Select Case intCount
  63. 	Case 0:
  64. 		WScript.Echo vbCrLf & "All optional Language Pack updates were either" _
  65. 		           & vbCrLf & "installed or hidden already, no change required"
  66. 	Case 1:
  67. 		WScript.Echo vbCrLf & "Hidden 1 optional Language Pack update"
  68. 	Case Else:
  69. 		WScript.Echo vbCrLf & "Hidden " & intCount & " optional Language Pack updates"
  70. End Select
  71.  
  72. 	If intSkipped = 1 Then
  73. 		WScript.Echo vbCrLf & "Skipped l Language Pack update"
  74. 	ElseIf intSkipped > 1 Then
  75. 		WScript.Echo vbCrLf & "Skipped " & intSkipped & " Language Pack updates"
  76. 	End If
  77.  
  78. WScript.Quit intCount
  79.  
  80.  
  81. Sub Syntax
  82. 	Dim strMsg
  83. 	strMsg = vbCrLf _
  84. 	       & "DisableLanguagePackUpdates.vbs,  version 1.00" _
  85. 	       & vbCrLf _
  86. 	       & "Hide all Language Pack updates in Windows Update" _
  87. 	       & vbCrLf & vbCrLf _
  88. 	       & "Usage:  DisableSilverlightUpdates.vbs  /X:pattern" _
  89. 	       & vbCrLf & vbCrLf _
  90. 	       & "Where:  /X:pattern   specifies the eXceptions, i.e. the updates NOT to be" _
  91. 	       & vbCrLf _
  92. 	       & "                     hidden, as a regular expression pattern to test against" _
  93. 	       & vbCrLf _
  94. 	       & "                     the Language Pack title (e.g. /X:Czech)" _
  95. 	       & vbCrLf & vbCrLf _
  96. 	       & "Notes:  Even if you do not wish to install Language Packs, Windows Update" _
  97. 	       & vbCrLf _
  98. 	       & "        will offer 33 Language Packs as optional update. You can hide each" _
  99. 	       & vbCrLf _
  100. 	       & "        of these manually, but why not let this script automate that for you?" _
  101. 	       & vbCrLf _
  102. 	       & "        Based on a script written in JScript by Tony Marques" _
  103. 	       & vbCrLf _
  104. 	       & "        (https://superuser.com/a/1009947)" _
  105. 	       & vbCrLf _
  106. 	       & "        This script's return code is the number of Language Pack updates" _
  107. 	       & vbCrLf _
  108. 	       & "        hidden by this script, or -1 in case of command line errors." _
  109. 	       & vbCrLf & vbCrLf _
  110. 	       & "Written by Rob van der Woude" _
  111. 	       & vbCrLf _
  112. 	       & "http://www.robvanderwoude.com"
  113. 	WScript.Echo strMsg
  114. 	WScript.Quit -1
  115. End Sub
  116.  

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