this.Blog.Find(entry => entry.IsHelpful);
 Tuesday, April 22, 2008
Getting the SysInternals Suite, Ruby style
John Robbins at Wintellect put out a nice blog post about using a PowerShell script to download and install the excellent suite of tools provided by Sysinternals. I absolutely love the *concept* of PowerShell and the ability to harness the power of .Net at the command prompt. The one downside to it is that I find the syntax to be a bit too verbose than what I normally expect out of a scripting language. YMMV.
Anyway, in an effort to stay on top of my (limited) Ruby skills, I have ported his implementation to Ruby: #!/usr/bin/env ruby
require 'net/http' require 'zip/zip'
def usage puts "" puts "Downloads and extracts all the tools from Sysinternals" puts "" puts "Usage: ruby download_sysinternals.rb <extract-directory> [<save-directory>]" puts "Required Parameter :" puts " <extract-directory> : The directory where the SysinternalsSuite.zip" puts " tools are extracted." puts "Optional Parameters :" puts " <save-directory> : Saves SysinternalsSuite.zip to the specified" puts " directory. If not specified, the .ZIP file " puts " is not saved." puts " -? : Display this usage information" puts "" puts "" Kernel#exit end
def create_directory_if_needed(dir) File.makedirs(dir) unless File.exist?(dir) end
def download_sysinternals_zip_file(download_dir) puts "Downloading SysinternalsSuite.zip file" url = URI.parse('http://download.sysinternals.com/Files/SysinternalsSuite.zip') req = Net::HTTP::Get.new(url.path) resp = Net::HTTP.start(url.host, url.port) { |http| http.request(req) } puts "Saving SysinternalsSuite.zip to: #{download_dir}" file_name = "#{download_dir}/SysinternalsSuite.zip" delete_file_if_exists(file_name) open(file_name, "wb") { |file| file.write(resp.body) } puts "Finished downloading" end
def extract_zip_file(zip_file, extract_dir) puts "Extracting zip file to: #{extract_dir}" Zip::ZipFile.open(zip_file) do |zip| zip.each do |entry| file_name = "#{extract_dir}/#{entry.to_s}" puts "Extracting #{file_name}" # you will need to run this as an admin if # you have sysinternals stuff in "Program Files" delete_file_if_exists(file_name) entry.extract(file_name) end end
puts "Finished extracting zip file" end
def delete_file_if_exists(file_name) File.delete(file_name) if File.exist?(file_name) end
# here we go!!! usage if ( ARGV.empty? || ARGV[0] == "-?" )
extract_dir = ARGV[0] save_dir = ARGV.length > 1 ? ARGV[1] : ENV["TEMP"]
# download the file create_directory_if_needed(save_dir) download_sysinternals_zip_file(save_dir)
# extract the zip file create_directory_if_needed(extract_dir) zip_file = "#{save_dir}/SysinternalsSuite.zip" extract_zip_file(zip_file, extract_dir)
# clean up after ourselves delete_file_if_exists(zip_file) if ARGV.length < 1
Tuesday, April 22, 2008 6:59:08 AM (Eastern Standard Time, UTC-05:00) Powershell | Ruby | Sysinternals
|

Subscribe to this feed
 Email Me
 Follow Me On Twitter
Search
Navigation
Tag Cloud
Archive
Blogroll
|