コード例 #1
0
        public ServiceHandle CreateService(string serviceName, string displayName, string binaryPath, ServiceType serviceType, ServiceStartType startupType, ErrorSeverity errorSeverity, Win32ServiceCredentials credentials)
        {
            ServiceHandle service = Win32.CreateServiceW(this, serviceName, displayName, ServiceControlAccessRights.All, serviceType, startupType, errorSeverity,
                                                         binaryPath, null, IntPtr.Zero, null, credentials.UserName, credentials.Password);

            if (service.IsInvalid)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return(service);
        }
コード例 #2
0
        public virtual bool TryOpenService(string serviceName, ServiceControlAccessRights desiredControlAccess, out ServiceHandle serviceHandle,
                                           out Win32Exception errorException)
        {
            ServiceHandle service = Win32.OpenServiceW(this, serviceName, desiredControlAccess);

            if (service.IsInvalid)
            {
                errorException = new Win32Exception(Marshal.GetLastWin32Error());
                serviceHandle  = null;
                return(false);
            }

            serviceHandle  = service;
            errorException = null;
            return(true);
        }