Created
January 31, 2012 22:23
-
-
Save stevenharman/1713431 to your computer and use it in GitHub Desktop.
A Win32OLE object wrapper that does the right thing. #lolwindows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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