Method: Puppet::Util::Windows::Service.open_service
- Defined in:
- lib/puppet/util/windows/service.rb
.open_service(service_name, scm_access, service_access) {|service| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Opens a connection to the SCManager on windows then uses that handle to create a handle to a specific service in windows corresponding to service_name
this function takes a block that executes within the context of the open service handler, and will close the service and SCManager handles once the block finishes
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/puppet/util/windows/service.rb', line 302 def open_service(service_name, scm_access, service_access, &block) service = FFI::Pointer::NULL_HANDLE result = nil open_scm(scm_access) do |scm| service = OpenServiceW(scm, wide_string(service_name), service_access) raise Puppet::Util::Windows::Error, _("Failed to open a handle to the service") if service == FFI::Pointer::NULL_HANDLE result = yield service end result ensure CloseServiceHandle(service) end |