Class: IronHammer::Deploy::WMIService
- Inherits:
-
Object
- Object
- IronHammer::Deploy::WMIService
- Defined in:
- lib/iron_hammer/deploy/wmi_service.rb
Instance Method Summary collapse
- #create!(params = {}) ⇒ Object
-
#initialize(params = {}) ⇒ WMIService
constructor
A new instance of WMIService.
- #service(name) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ WMIService
Returns a new instance of WMIService.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/iron_hammer/deploy/wmi_service.rb', line 42 def initialize params ={} computer = params[:computer] user = params[:user] password = params[:password] if user && password @wmi = WIN32OLE.new("WbemScripting.SWbemLocator").ConnectServer(computer, "root\\cimv2", user, password) else @wmi = WIN32OLE.connect("winmgmts:{impersonationLevel=impersonate}!\\\\#{computer}\\root\\cimv2") end end |
Instance Method Details
#create!(params = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/iron_hammer/deploy/wmi_service.rb', line 61 def create! params={} base_service.Create( params[:name] || raise(ArgumentError.new "You must specify a name when creating a service"), params[:display_name] || params[:name], params[:path] || raise(ArgumentError.new "You must specify a path when creating a service"), params[:service_type] || ServiceType::OWN_PROCESS, params[:error_control]|| ErrorControl::NORMAL, params[:start_mode] || StartMode::AUTOMATIC, params[:desktop_interact] || DesktopInteraction::DONT_INTERACT, params[:start_name], params[:start_password], params[:load_order_group], params[:load_order_group_dependencies], params[:service_dependencies] ) end |
#service(name) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/iron_hammer/deploy/wmi_service.rb', line 53 def service name services = @wmi.ExecQuery("SELECT * FROM Win32_Service WHERE Name = '#{name}'") services.each do |s| return WindowsService.new s end nil end |