Skip to content

Instantly share code, notes, and snippets.

@btm
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btm/23aad6661908b00ad752 to your computer and use it in GitHub Desktop.
Save btm/23aad6661908b00ad752 to your computer and use it in GitHub Desktop.
Use ruby to search Windows Updates for KB2918614
require 'rubygems'
require 'win32ole'
kb = "KB2918614"
start_time = Time.now
puts "Starting search for #{kb} at #{start_time}"
update_session = WIN32OLE.new("Microsoft.Update.Session")
update_searcher = update_session.CreateUpdateSearcher
update_searcher.Search('IsHidden=1 and IsInstalled=1')
total_count = update_searcher.GetTotalHistoryCount
puts "Found #{total_count} updates"
update_collection = update_searcher.QueryHistory(0, total_count)
update_collection.each do |item|
if item.Title =~ /#{kb}/
puts "#{kb} is installed"
# break # optionally bail out immediately for a slightly faster return
end
end
elapsed_time = Time.now - start_time
puts "Completed search in #{elapsed_time} seconds"
PS C:\Users\Administrator> ruby .\kb.rb
Starting search for KB2918614 at 2014-10-13 18:10:25 -0700
Found 199 updates
KB2918614 is installed
Completed search in 10.609375 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment