C# Class ServiceTools.ServiceInstaller

Installs and provides functionality for handling windows services
Datei anzeigen Open project: wirepair/GHAST_priv8

Public Methods

Method Description
GetServiceStatus ( string ServiceName ) : ServiceState

Takes a service name and returns the ServiceState of the corresponding service

Install ( string ServiceName, string DisplayName, string FileName ) : void

Takes a service name, a service display name and the path to the service executable and installs the windows service.

InstallAndStart ( string ServiceName, string DisplayName, string FileName ) : void

Takes a service name, a service display name and the path to the service executable and installs / starts the windows service.

ServiceInstaller ( ) : System

ServiceIsInstalled ( string ServiceName ) : bool

Accepts a service name and returns true if the service with that service name exists

StartService ( string Name ) : void

Takes a service name and starts it

StopService ( string Name ) : void

Stops the provided windows service

Uninstall ( string ServiceName ) : void

Takes a service name and tries to stop and then uninstall the windows serviceError

Private Methods

Method Description
CloseServiceHandle ( IntPtr hSCObject ) : int
ControlService ( IntPtr hService, ServiceControl dwControl, SERVICE_STATUS lpServiceStatus ) : int
CreateService ( IntPtr hSCManager, string lpServiceName, string lpDisplayName, ServiceRights dwDesiredAccess, int dwServiceType, ServiceBootFlag dwStartType, ServiceError dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, IntPtr lpdwTagId, string lpDependencies, string lp, string lpPassword ) : IntPtr
DeleteService ( IntPtr hService ) : int
GetServiceStatus ( IntPtr hService ) : ServiceState

Gets the service state by using the handle of the provided windows service

OpenSCManager ( ServiceManagerRights Rights ) : IntPtr

Opens the service manager

OpenSCManager ( string lpMachineName, string lpDatabaseName, ServiceManagerRights dwDesiredAccess ) : IntPtr
OpenService ( IntPtr hSCManager, string lpServiceName, ServiceRights dwDesiredAccess ) : IntPtr
QueryServiceStatus ( IntPtr hService, SERVICE_STATUS lpServiceStatus ) : int
StartService ( IntPtr hService, int dwNumServiceArgs, int lpServiceArgVectors ) : int
StartService ( IntPtr hService ) : void

Stars the provided windows service

StopService ( IntPtr hService ) : void

Stops the provided windows service

WaitForServiceStatus ( IntPtr hService, ServiceState WaitStatus, ServiceState DesiredStatus ) : bool

Returns true when the service status has been changes from wait status to desired status ,this method waits around 10 seconds for this operation.

Method Details

GetServiceStatus() public static method

Takes a service name and returns the ServiceState of the corresponding service
public static GetServiceStatus ( string ServiceName ) : ServiceState
ServiceName string The service name that we will check for his ServiceState
return ServiceState

Install() public static method

Takes a service name, a service display name and the path to the service executable and installs the windows service.
public static Install ( string ServiceName, string DisplayName, string FileName ) : void
ServiceName string The service name that this service will have
DisplayName string The display name that this service will have
FileName string The path to the executable of the service
return void

InstallAndStart() public static method

Takes a service name, a service display name and the path to the service executable and installs / starts the windows service.
public static InstallAndStart ( string ServiceName, string DisplayName, string FileName ) : void
ServiceName string The service name that this service will have
DisplayName string The display name that this service will have
FileName string The path to the executable of the service
return void

ServiceInstaller() public method

public ServiceInstaller ( ) : System
return System

ServiceIsInstalled() public static method

Accepts a service name and returns true if the service with that service name exists
public static ServiceIsInstalled ( string ServiceName ) : bool
ServiceName string The service name that we will check for existence
return bool

StartService() public static method

Takes a service name and starts it
public static StartService ( string Name ) : void
Name string The service name
return void

StopService() public static method

Stops the provided windows service
public static StopService ( string Name ) : void
Name string The service name that will be stopped
return void

Uninstall() public static method

Takes a service name and tries to stop and then uninstall the windows serviceError
public static Uninstall ( string ServiceName ) : void
ServiceName string The windows service name to uninstall
return void