PeanutButter
Loading...
Searching...
No Matches
PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil Class Reference

The legacy, native WindowsServiceUtil which uses the win32api to provide service management. More...

Inheritance diagram for PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil:
PeanutButter.WindowsServiceManagement.IWindowsServiceUtil

Public Member Functions

 NativeWindowsServiceUtil (string serviceName)
 NativeWindowsServiceUtil (string serviceName, string displayName, string serviceCommandline)
 Construct a windows service util with service name, description and commandline - typically the constructor used when registering a service for the first time.
void Uninstall ()
 Uninstalls the service. If the service is not found by name, does nothing.
void Uninstall (bool waitForUninstall)
 Uninstalls the service. If the service is not found by name, does nothing. Will wait for the uninstallation to complete.
void Uninstall (ControlOptions options)
 More control over uninstallation.
Parameters
options

void InstallAndStart ()
 Installs the service as AutoStart and starts it, waiting for the service to report that it's running.
void InstallAndStart (bool waitForStart)
 Install and start the service as AutoStarting, with control over whether to wait for the service to have properly started.
Parameters
wait

void InstallAndStart (ServiceStartupTypes startupType, bool waitForStart)
 Install and start the service, with control over whether to wait for the service to have properly started.
Parameters
startupType
wait

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.
Parameters
startupType

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.
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.
Parameters
wait

void Stop ()
 Stop the service and wait for it to be running.
void Stop (bool wait)
 Start the service Explicitly wait or not for it to stop.
Parameters
wait

void Stop (ControlOptions options)
 Stop the service with the provided control options.
  • when Force is provided, if the service doesn't stop within the allowed period, it will be killed.
Parameters
options

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.
KillServiceResult KillService ()
 Kills the service, if running.
Returns

void ConfigureStartup (ServiceStartupTypes startupType)
 Configure the service's startup type.
Parameters
startupType

Static Public Member Functions

static IWindowsServiceUtil GetServiceByPid (int pid)
 Attempt to load a WindowsServiceUtil by the pid of a running process.
static WindowsServiceUtil GetServiceByPath (string path)
 Attempt to load a WindowsServiceUtil by a full path to the executable.

Properties

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 IsPaused [get]
 Whether or not the service is paused.
  • always false for an uninstalled service

bool IsRunning [get]
 Whether or not the service is running.
  • always false for an uninstalled service

string ServiceName [get]
 The name of the service, usable from, eg 'net stop {name}'.
bool IsStoppable [get]
 True if the service is in a stoppable state.
bool IsStartable [get]
 True if the service is in a startable state.
string DisplayName [get, set]
 The name displayed in the service manager (service.msc)
string Commandline [get]
 The full commandline for this service.
string ServiceExe [get]
 The path to the service executable.
string[] Arguments [get]
 The arguments that the service is started with.
int ServiceStateExtraWaitSeconds [get, set]
 In addition to the amount of time that the service control manager would normally wait for a service to respond to a control request (typically 30s, but this can be overridden on the host machine), the util will wait this number of seconds extra for your service to change state on blocking control requests.
ServiceState State [get]
 The current state of this service.
bool IsInstalled [get]
 Whether or not the service is installed -> this is a shortcut to check startup type vs unknown.
bool IsMarkedForDelete [get]
 Test if the service is marked for deletion.
int ServicePID [get]
 The process id for a running process (0 when not running)
ServiceStartupTypes StartupType [get]
 The startup type of the service.

Detailed Description

The legacy, native WindowsServiceUtil which uses the win32api to provide service management.

Constructor & Destructor Documentation

◆ NativeWindowsServiceUtil()

PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.NativeWindowsServiceUtil ( string serviceName,
string displayName,
string serviceCommandline )

Construct a windows service util with service name, description and commandline - typically the constructor used when registering a service for the first time.

Parameters
serviceName
displayName
serviceCommandline

Member Function Documentation

◆ ConfigureStartup()

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.ConfigureStartup ( ServiceStartupTypes startupType)

Configure the service's startup type.

Parameters
startupType

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Continue() [1/2]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Continue ( )

Continue the service, waiting for it to enter the continued state.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Continue() [2/2]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Continue ( bool wait)

Continue the service Explicitly wait or not for it to continue.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Disable()

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Disable ( )

Disable the service from running.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ GetServiceByPath()

WindowsServiceUtil PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.GetServiceByPath ( string path)
static

Attempt to load a WindowsServiceUtil by a full path to the executable.

Parameters
path
Returns
Exceptions
ArgumentException

◆ GetServiceByPid()

IWindowsServiceUtil PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.GetServiceByPid ( int pid)
static

Attempt to load a WindowsServiceUtil by the pid of a running process.

Parameters
pid
Returns

◆ Install() [1/2]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Install ( )

Installs the service with automatic start. Will error if the service is already found by name.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Install() [2/2]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Install ( ServiceStartupTypes startupType)

Install with the provided startup type.

Parameters
startupType

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ InstallAndStart() [1/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.InstallAndStart ( )

Installs the service as AutoStart and starts it, waiting for the service to report that it's running.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ InstallAndStart() [2/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.InstallAndStart ( bool waitForStart)

Install and start the service as AutoStarting, with control over whether to wait for the service to have properly started.

Parameters
wait

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ InstallAndStart() [3/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.InstallAndStart ( ServiceStartupTypes startupType,
bool waitForStart )

Install and start the service, with control over whether to wait for the service to have properly started.

Parameters
startupType
wait

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ KillService()

KillServiceResult PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.KillService ( )

Kills the service, if running.

Returns

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Pause() [1/2]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Pause ( )

Pause the service, waiting for it to enter the paused state.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Pause() [2/2]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Pause ( bool wait)

Pause the service Explicitly wait or not for it to pause.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ SetAutomaticStart()

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.SetAutomaticStart ( )

Set the service to automatically start with the host system.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ SetManualStart()

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.SetManualStart ( )

Set the service to require manual start.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Start() [1/2]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Start ( )

Start the service and wait for it to be running.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Start() [2/2]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Start ( bool wait)

Start the service Explicitly wait or not for it to start.

Parameters
wait

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Stop() [1/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Stop ( )

Stop the service and wait for it to be running.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Stop() [2/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Stop ( bool wait)

Start the service Explicitly wait or not for it to stop.

Parameters
wait

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Stop() [3/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Stop ( ControlOptions options)

Stop the service with the provided control options.

  • when Force is provided, if the service doesn't stop within the allowed period, it will be killed.
Parameters
options

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Uninstall() [1/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Uninstall ( )

Uninstalls the service. If the service is not found by name, does nothing.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Uninstall() [2/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Uninstall ( bool waitForUninstall)

Uninstalls the service. If the service is not found by name, does nothing. Will wait for the uninstallation to complete.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Uninstall() [3/3]

void PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Uninstall ( ControlOptions options)

More control over uninstallation.

Parameters
options

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

Property Documentation

◆ Arguments

string [] PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Arguments
get

The arguments that the service is started with.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ Commandline

string PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.Commandline
get

The full commandline for this service.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ DisplayName

string PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.DisplayName
getset

The name displayed in the service manager (service.msc)

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ IsDisabled

bool PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.IsDisabled
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.

◆ IsInstalled

bool PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.IsInstalled
get

Whether or not the service is installed -> this is a shortcut to check startup type vs unknown.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ IsMarkedForDelete

bool PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.IsMarkedForDelete
get

Test if the service is marked for deletion.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ IsPaused

bool PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.IsPaused
get

Whether or not the service is paused.

  • always false for an uninstalled service

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ IsRunning

bool PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.IsRunning
get

Whether or not the service is running.

  • always false for an uninstalled service

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ IsStartable

bool PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.IsStartable
get

True if the service is in a startable state.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ IsStoppable

bool PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.IsStoppable
get

True if the service is in a stoppable state.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ ServiceExe

string PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.ServiceExe
get

The path to the service executable.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ ServiceName

string PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.ServiceName
get

The name of the service, usable from, eg 'net stop {name}'.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ ServicePID

int PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.ServicePID
get

The process id for a running process (0 when not running)

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ StartupType

ServiceStartupTypes PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.StartupType
get

The startup type of the service.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.

◆ State

ServiceState PeanutButter.WindowsServiceManagement.NativeWindowsServiceUtil.State
get

The current state of this service.

Implements PeanutButter.WindowsServiceManagement.IWindowsServiceUtil.


The documentation for this class was generated from the following file:
  • source/Win32Service/PeanutButter.WindowsServiceManagement/NativeWindowsServiceUtil.cs