PeanutButter
|
The cross-environment WindowsServiceUtil, backed by commands to sc.exe. More...
Public Member Functions | |||||
WindowsServiceUtil (string serviceName) | |||||
Used to query existing services. | |||||
WindowsServiceUtil (string serviceName, string displayName, string commandline) | |||||
Used to install a service, but still provides the same query interface. | |||||
void | Refresh () | ||||
Force a refresh of the current service state. | |||||
void | Start () | ||||
Start the service and wait for it to be running. | |||||
void | Start (bool wait) | ||||
Start the service Explicitly wait or not for it to start.
| |||||
void | Stop () | ||||
Stop the service and wait for it to be running. | |||||
void | Stop (ControlOptions options) | ||||
Stop the service with the provided control options.
| |||||
void | Stop (bool wait) | ||||
Start the service Explicitly wait or not for it to stop.
| |||||
void | Pause () | ||||
Pause the service, waiting for it to enter the paused state. | |||||
void | Pause (bool wait) | ||||
Pause the service Explicitly wait or not for it to pause. | |||||
void | Continue () | ||||
Continue the service, waiting for it to enter the continued state. | |||||
void | Continue (bool wait) | ||||
Continue the service Explicitly wait or not for it to continue. | |||||
void | ConfigureStartup (ServiceStartupTypes startupType) | ||||
Configure the service's startup type.
| |||||
void | Install () | ||||
Installs the service with automatic start. Will error if the service is already found by name. | |||||
void | Install (ServiceStartupTypes startupType) | ||||
Install with the provided startup type.
| |||||
void | Uninstall () | ||||
Uninstalls the service. If the service is not found by name, does nothing. | |||||
void | Uninstall (bool wait) | ||||
Uninstalls the service. If the service is not found by name, does nothing. Will wait for the uninstallation to complete. | |||||
void | Uninstall (ControlOptions controlOptions) | ||||
More control over uninstallation.
| |||||
void | InstallAndStart () | ||||
Installs the service as AutoStart and starts it, waiting for the service to report that it's running. | |||||
void | InstallAndStart (bool wait) | ||||
Install and start the service as AutoStarting, with control over whether to wait for the service to have properly started.
| |||||
void | InstallAndStart (ServiceStartupTypes startupType, bool wait) | ||||
Install and start the service, with control over whether to wait for the service to have properly started.
| |||||
void | Disable () | ||||
Disable the service from running. | |||||
void | SetAutomaticStart () | ||||
Set the service to automatically start with the host system. | |||||
void | SetManualStart () | ||||
Set the service to require manual start. | |||||
KillServiceResult | KillService () | ||||
Kills the service, if running.
|
Static Public Member Functions | |
static IWindowsServiceUtil | GetServiceByPid (int pid) |
Attempt to load a WindowsServiceUtil by the pid of a running process. | |
static IWindowsServiceUtil | GetServiceByPath (string path) |
Attempt to load a WindowsServiceUtil by a full path to the executable. |
Properties | |
string | ServiceName [get] |
The name of the service, usable from, eg 'net stop {name}'. | |
string | DisplayName [get] |
The name displayed in the service manager (service.msc) | |
ServiceState | State [get] |
The current state of this service. | |
ServiceStartupTypes | StartupType = ServiceStartupTypes.Unknown [get] |
The startup type of the service. | |
ServiceState[] | AllowedStates [get] |
The states which this service may transition to, from the current state. | |
bool | IsDisabled [get] |
Whether or not the service is disabled -> this is a shortcut to check the startup type vs the disabled startup type. | |
bool | IsInstalled [get] |
Whether or not the service is installed -> this is a shortcut to check startup type vs unknown. | |
bool | IsRunning [get] |
Whether or not the service is running.
| |
bool | IsPaused [get] |
Whether or not the service is paused.
| |
bool | IsMarkedForDelete [get] |
Test if the service is marked for deletion. | |
bool | IsStoppable [get] |
True if the service is in a stoppable state. | |
bool | IsStartable [get] |
True if the service is in a startable state. | |
int | ServicePID [get] |
The process id for a running process (0 when not running) | |
string | ServiceExe [get] |
The path to the service executable. | |
string[] | Arguments [get] |
The arguments that the service is started with. | |
string | Commandline [get] |
The full commandline for this service. | |
int | ServiceControlTimeoutSeconds = DEFAULT_SERVICE_CONTROL_TIMEOUT_SECONDS [get, set] |
The timeout, in seconds, whilst waiting for service control operations to complete. Override this value if you have a service which is particularly slow to respond to control requests, eg takes long to start up. | |
int | PollIntervalMilliseconds = DEFAULT_POLL_INTERVAL_MILLISECONDS [get, set] |
The interval, in milliseconds, between polling service state whilst running a blocking control operation, to determine if the desired state has been reached. |
The cross-environment WindowsServiceUtil, backed by commands to sc.exe.
PeanutButter.WindowsServiceManagement.WindowsServiceUtil.WindowsServiceUtil | ( | string | serviceName | ) |
Used to query existing services.
serviceName |
PeanutButter.WindowsServiceManagement.WindowsServiceUtil.WindowsServiceUtil | ( | string | serviceName, |
string | displayName, | ||
string | commandline ) |
Used to install a service, but still provides the same query interface.
serviceName | |
displayName | |
commandline |
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.ConfigureStartup | ( | ServiceStartupTypes | startupType | ) |
Configure the service's startup type.
startupType |
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Continue | ( | ) |
Continue the service, waiting for it to enter the continued state.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Continue | ( | bool | wait | ) |
Continue the service Explicitly wait or not for it to continue.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Disable | ( | ) |
Disable the service from running.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
static |
Attempt to load a WindowsServiceUtil by a full path to the executable.
path |
ArgumentException |
|
static |
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Install | ( | ) |
Installs the service with automatic start. Will error if the service is already found by name.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Install | ( | ServiceStartupTypes | startupType | ) |
Install with the provided startup type.
startupType |
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.InstallAndStart | ( | ) |
Installs the service as AutoStart and starts it, waiting for the service to report that it's running.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.InstallAndStart | ( | bool | wait | ) |
Install and start the service as AutoStarting, with control over whether to wait for the service to have properly started.
wait |
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.InstallAndStart | ( | ServiceStartupTypes | startupType, |
bool | wait ) |
Install and start the service, with control over whether to wait for the service to have properly started.
startupType | |
wait |
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
KillServiceResult PeanutButter.WindowsServiceManagement.WindowsServiceUtil.KillService | ( | ) |
Kills the service, if running.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Pause | ( | ) |
Pause the service, waiting for it to enter the paused state.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Pause | ( | bool | wait | ) |
Pause the service Explicitly wait or not for it to pause.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.SetAutomaticStart | ( | ) |
Set the service to automatically start with the host system.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.SetManualStart | ( | ) |
Set the service to require manual start.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Start | ( | ) |
Start the service and wait for it to be running.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Start | ( | bool | wait | ) |
Start the service Explicitly wait or not for it to start.
wait |
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Stop | ( | ) |
Stop the service and wait for it to be running.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Stop | ( | bool | wait | ) |
Start the service Explicitly wait or not for it to stop.
wait |
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Stop | ( | ControlOptions | options | ) |
Stop the service with the provided control options.
options |
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Uninstall | ( | ) |
Uninstalls the service. If the service is not found by name, does nothing.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Uninstall | ( | bool | wait | ) |
Uninstalls the service. If the service is not found by name, does nothing. Will wait for the uninstallation to complete.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
void PeanutButter.WindowsServiceManagement.WindowsServiceUtil.Uninstall | ( | ControlOptions | controlOptions | ) |
More control over uninstallation.
options |
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
The arguments that the service is started with.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
The full commandline for this service.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
The name displayed in the service manager (service.msc)
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
Whether or not the service is disabled -> this is a shortcut to check the startup type vs the disabled startup type.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
Whether or not the service is installed -> this is a shortcut to check startup type vs unknown.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
Test if the service is marked for deletion.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
Whether or not the service is paused.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
Whether or not the service is running.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
True if the service is in a startable state.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
True if the service is in a stoppable state.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
The path to the service executable.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
The name of the service, usable from, eg 'net stop {name}'.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
The process id for a running process (0 when not running)
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
The startup type of the service.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.
|
get |
The current state of this service.
Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.