From 6fa976496aec21b01d28be7c24ad2525b9996190 Mon Sep 17 00:00:00 2001 From: Shravani Roy Date: Wed, 13 Apr 2022 18:05:28 +0530 Subject: [PATCH] Updating OpenService Signed-off-by: Shravani Roy --- lib/win32/service.rb | 84 ++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/lib/win32/service.rb b/lib/win32/service.rb index af8c5aa..d3e0846 100644 --- a/lib/win32/service.rb +++ b/lib/win32/service.rb @@ -342,9 +342,9 @@ def initialize(options = {}) raise TypeError if host && !host.is_a?(String) begin - handle_scm = OpenSCManager(host, nil, SC_MANAGER_CREATE_SERVICE) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_CREATE_SERVICE) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 # Display name defaults to service_name opts["display_name"] ||= service_name @@ -504,9 +504,9 @@ def self.configure(options = {}) end begin - handle_scm = OpenSCManager(host, nil, SC_MANAGER_CONNECT) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_CONNECT) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 desired_access = SERVICE_CHANGE_CONFIG @@ -514,13 +514,13 @@ def self.configure(options = {}) desired_access |= SERVICE_START end - handle_scs = OpenService( + handle_scs = OpenServiceA( handle_scm, service, desired_access ) - FFI.raise_windows_error("OpenService") if handle_scs == 0 + FFI.raise_windows_error("OpenServiceA") if handle_scs == 0 dependencies = opts["dependencies"] @@ -601,11 +601,11 @@ def self.exists?(service, host = nil) bool = false begin - handle_scm = OpenSCManager(host, nil, SC_MANAGER_ENUMERATE_SERVICE) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_ENUMERATE_SERVICE) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 - handle_scs = OpenService(handle_scm, service, SERVICE_QUERY_STATUS) + handle_scs = OpenServiceA(handle_scm, service, SERVICE_QUERY_STATUS) bool = true if handle_scs > 0 ensure close_service_handle(handle_scm) @@ -628,9 +628,9 @@ def self.exists?(service, host = nil) # Service.get_display_name('W32Time') => 'Windows Time' # def self.get_display_name(service, host = nil) - handle_scm = OpenSCManager(host, nil, SC_MANAGER_CONNECT) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_CONNECT) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 display_name = FFI::MemoryPointer.new(260) display_size = FFI::MemoryPointer.new(:ulong) @@ -644,7 +644,7 @@ def self.get_display_name(service, host = nil) display_size ) - FFI.raise_windows_error("OpenSCManager") unless bool + FFI.raise_windows_error("OpenSCManagerA") unless bool ensure close_service_handle(handle_scm) end @@ -665,9 +665,9 @@ def self.get_display_name(service, host = nil) # Service.get_service_name('Windows Time') => 'W32Time' # def self.get_service_name(display_name, host = nil) - handle_scm = OpenSCManager(host, nil, SC_MANAGER_CONNECT) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_CONNECT) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 service_name = FFI::MemoryPointer.new(260) service_size = FFI::MemoryPointer.new(:ulong) @@ -702,14 +702,14 @@ def self.get_service_name(display_name, host = nil) # Service.start('SomeSvc', 'foo', 'hello') => self # def self.start(service, host = nil, *args) - handle_scm = OpenSCManager(host, nil, SC_MANAGER_CONNECT) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_CONNECT) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 begin - handle_scs = OpenService(handle_scm, service, SERVICE_START) + handle_scs = OpenServiceA(handle_scm, service, SERVICE_START) - FFI.raise_windows_error("OpenService") if handle_scs == 0 + FFI.raise_windows_error("OpenServiceA") if handle_scs == 0 num_args = 0 @@ -813,14 +813,14 @@ def self.resume(service, host = nil) # Service.delete('SomeService') => self # def self.delete(service, host = nil) - handle_scm = OpenSCManager(host, nil, SC_MANAGER_CREATE_SERVICE) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_CREATE_SERVICE) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 begin - handle_scs = OpenService(handle_scm, service, DELETE) + handle_scs = OpenServiceA(handle_scm, service, DELETE) - FFI.raise_windows_error("OpenService") if handle_scs == 0 + FFI.raise_windows_error("OpenServiceA") if handle_scs == 0 unless DeleteService(handle_scs) FFI.raise_windows_error("DeleteService") @@ -848,14 +848,14 @@ def self.delete(service, host = nil) def self.config_info(service, host = nil) raise TypeError if host && !host.is_a?(String) - handle_scm = OpenSCManager(host, nil, SC_MANAGER_ENUMERATE_SERVICE) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_ENUMERATE_SERVICE) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 begin - handle_scs = OpenService(handle_scm, service, SERVICE_QUERY_CONFIG) + handle_scs = OpenServiceA(handle_scm, service, SERVICE_QUERY_CONFIG) - FFI.raise_windows_error("OpenService") if handle_scs == 0 + FFI.raise_windows_error("OpenServiceA") if handle_scs == 0 # First, get the buf size needed bytes = FFI::MemoryPointer.new(:ulong) @@ -968,9 +968,9 @@ def self.services(host = nil, group = nil) raise TypeError unless group.is_a?(String) # Avoid strange errors end - handle_scm = OpenSCManager(host, nil, SC_MANAGER_ENUMERATE_SERVICE) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_ENUMERATE_SERVICE) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 bytes_needed = FFI::MemoryPointer.new(:ulong) services_returned = FFI::MemoryPointer.new(:ulong) @@ -1036,13 +1036,13 @@ def self.services(host = nil, group = nil) service_flags = struct[:ServiceStatusProcess][:dwServiceFlags] begin - handle_scs = OpenService( + handle_scs = OpenServiceA( handle_scm, service_name, SERVICE_QUERY_CONFIG ) - FFI.raise_windows_error("OpenService") if handle_scs == 0 + FFI.raise_windows_error("OpenServiceA") if handle_scs == 0 config_struct = get_config_info(handle_scs) @@ -1197,17 +1197,17 @@ def self.services(host = nil, group = nil) # a problem of some kind. # def self.delayed_start(service, host = nil) - handle_scm = OpenSCManager(host, nil, SC_MANAGER_ENUMERATE_SERVICE) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_ENUMERATE_SERVICE) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 - handle_scs = OpenService( + handle_scs = OpenServiceA( handle_scm, service, SERVICE_QUERY_CONFIG ) - FFI.raise_windows_error("OpenService") if handle_scs == 0 + FFI.raise_windows_error("OpenServiceA") if handle_scs == 0 delayed_start_buf = get_config2_info(handle_scs, SERVICE_CONFIG_DELAYED_AUTO_START_INFO) if delayed_start_buf.is_a?(FFI::MemoryPointer) @@ -1252,12 +1252,12 @@ def self.close_service_handle(handle) # @see Windows::ServiceConstants # def self.open_service(scm_handle, service_name, desired_access) - service_handle = OpenService( + service_handle = OpenServiceA( scm_handle, service_name, desired_access ) - FFI.raise_windows_error("OpenService") if service_handle == 0 + FFI.raise_windows_error("OpenServiceA") if service_handle == 0 if block_given? yield service_handle @@ -1289,8 +1289,8 @@ def self.open_service(scm_handle, service_name, desired_access) # @see Windows::ServiceConstants # def self.open_sc_manager(host = nil, desired_access = SC_MANAGER_CONNECT) - scm_handle = OpenSCManager(host, nil, desired_access) - FFI.raise_windows_error("OpenSCManager") if scm_handle == 0 + scm_handle = OpenSCManagerA(host, nil, desired_access) + FFI.raise_windows_error("OpenSCManagerA") if scm_handle == 0 if block_given? yield scm_handle @@ -1635,14 +1635,14 @@ def self.get_service_type(service_type) # A shortcut method that simplifies the various service control methods. # def self.send_signal(service, host, service_signal, control_signal) - handle_scm = OpenSCManager(host, nil, SC_MANAGER_CONNECT) + handle_scm = OpenSCManagerA(host, nil, SC_MANAGER_CONNECT) - FFI.raise_windows_error("OpenSCManager") if handle_scm == 0 + FFI.raise_windows_error("OpenSCManagerA") if handle_scm == 0 begin - handle_scs = OpenService(handle_scm, service, service_signal) + handle_scs = OpenServiceA(handle_scm, service, service_signal) - FFI.raise_windows_error("OpenService") if handle_scs == 0 + FFI.raise_windows_error("OpenServiceA") if handle_scs == 0 status = SERVICE_STATUS.new