Skip to content

Instantly share code, notes, and snippets.

@stevenharman
Created January 31, 2012 22:23
Show Gist options
  • Select an option

  • Save stevenharman/1713431 to your computer and use it in GitHub Desktop.

Select an option

Save stevenharman/1713431 to your computer and use it in GitHub Desktop.
A Win32OLE object wrapper that does the right thing. #lolwindows
# NOTE: I pulled this straight out of a Gem I wrote to help manage/automate
# the CI environment at VersionOne - hence the names and why you won't
# find Verver on http://rubygems.org. Sorry.
require 'delegate'
require 'win32ole'
module Verver
module IIS
# A thin wrapper around a WIN32OLE object that will automate
# management of IIS.
#
# iis_automation = Verver::IIS::Automation.new
# app_pool = iis_automation.get("ApplicationPool.name='DefaultAppPool'")
class Automation < SimpleDelegator
ADMIN_MONIKER = 'winmgmts:root\\WebAdministration'.freeze
def initialize(win_automation=WIN32OLE)
iis_automation = win_automation.connect(ADMIN_MONIKER)
super(iis_automation)
end
def method_missing(name, *args)
if __getobj__.ole_respond_to?(name)
__getobj__.send(name, *args)
else
super(name, *args)
end
end
def respond_to_missing?(name, include_private)
ole_respond_to?(name) || super(name, include_private)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment