/// Service control codes to be used with <see cref="ControlService"/> and <see cref="ControlServiceEx"/>
/// </summary>
publicenumServiceControl:uint
{
/// <summary>Notifies a service that it should stop. The hService handle must have the SERVICE_STOP access right. After sending the stop request to a service, you should not send other controls to the service.</summary>
SERVICE_CONTROL_STOP=0x00000001,
/// <summary>Notifies a service that it should pause. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.</summary>
SERVICE_CONTROL_PAUSE=0x00000002,
/// <summary>Notifies a paused service that it should resume. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.</summary>
SERVICE_CONTROL_CONTINUE=0x00000003,
/// <summary>
/// Notifies a service that it should report its current status information to the service control manager. The hService handle must have the SERVICE_INTERROGATE access right.
/// Note that this control is not generally useful as the SCM is aware of the current state of the service
/// </summary>
SERVICE_CONTROL_INTERROGATE=0x00000004,
/// <summary></summary>
SERVICE_CONTROL_SHUTDOWN=0x00000005,
/// <summary>Notifies a service that its startup parameters have changed. The hService handle must have the SERVICE_PAUSE_CONTINUE access right.</summary>
SERVICE_CONTROL_PARAMCHANGE=0x00000006,
/// <summary>Notifies a network service that there is a new component for binding. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead.</summary>
SERVICE_CONTROL_NETBINDADD=0x00000007,
/// <summary>Notifies a network service that a component for binding has been removed. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead.</summary>
SERVICE_CONTROL_NETBINDREMOVE=0x00000008,
/// <summary>Notifies a network service that a disabled binding has been enabled. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead.</summary>
SERVICE_CONTROL_NETBINDENABLE=0x00000009,
/// <summary>Notifies a network service that one of its bindings has been disabled. The hService handle must have the SERVICE_PAUSE_CONTINUE access right. However, this control code has been deprecated; use Plug and Play functionality instead.</summary>
/// Retrieves the configuration parameters of the specified service. Optional configuration parameters are available using the
@ -1410,6 +1470,53 @@ namespace Vanara.PInvoke
}
}
/// <summary>
/// Retrieves the current status of the specified service based on the specified information level.
/// </summary>
/// <param name="hService">
/// A handle to the service. This handle is returned by the <see cref="CreateService"/> or <see cref="OpenService"/> function, and it must have the <see cref="ServiceAccessTypes.SERVICE_QUERY_STATUS"/> access right.
/// For more information, see <see cref="https://docs.microsoft.com/en-gb/windows/desktop/Services/service-security-and-access-rights">Service Security and Access Rights.</see>
/// </param>
/// <param name="InfoLevel">The service attributes to be returned. Use <see cref="ServiceStatusType.SC_STATUS_PROCESS_INFO"/> to retrieve the service status information. The lpBuffer parameter is a pointer to a <see cref="SERVICE_STATUS_PROCESS" /> structure. Currently, no other information levels are defined.</param>
/// <param name="lpBuffer"></param>
/// <param name="cbBufSize"></param>
/// <param name="pcbBytesNeeded"></param>
/// <returns>
/// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error
/// Retrieves the current status of the specified service based on the specified information level.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="hService">
/// A handle to the service. This handle is returned by the <see cref="CreateService"/> or <see cref="OpenService"/> function, and it must have the <see cref="ServiceAccessTypes.SERVICE_QUERY_STATUS"/> access right.
/// For more information, see <see cref="https://docs.microsoft.com/en-gb/windows/desktop/Services/service-security-and-access-rights">Service Security and Access Rights.</see>
/// </param>
/// <param name="InfoLevel">The service attributes to be returned. Use <see cref="ServiceStatusType.SC_STATUS_PROCESS_INFO"/> to retrieve the service status information. The lpBuffer parameter is a pointer to a <see cref="SERVICE_STATUS_PROCESS" /> structure. Currently, no other information levels are defined.</param>
/// <param name="statusInfo">A variable that receives the service status information. The format of this data depends on the value of the dwInfoLevel parameter.</param>
/// <returns>
/// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error
/// <param name="hServiceStatus">A handle to the service. This handle is returned by the <see cref="OpenService"/> or <see cref="CreateService"/> function, and it must have the <see cref="ServiceAccessTypes.SERVICE_START"/> access right.</param>
/// <param name="dwNumServiceArgs">The number of strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.</param>
/// <param name="lpServiceArgVectors">The null-terminated strings to be passed to the ServiceMain function for the service as arguments. If there are no arguments, this parameter can be NULL. Otherwise, the first argument (lpServiceArgVectors[0]) is the name of the service, followed by any additional arguments (lpServiceArgVectors[1] through lpServiceArgVectors[dwNumServiceArgs-1]).</param>
/// <returns>If the function succeeds, the return value is true. If the function fails, the return value is false. To get extended error information, call GetLastError.</returns>
/// Marks the specified service for deletion from the service control manager database
/// </summary>
/// <param name="hServiceStatus">A handle to the service. This handle is returned by the <see cref="OpenService"/> or <see cref="CreateService"/> function, and it must have the <see cref="ACCESS_MASK.DELETE"/> access right.</param>
/// <returns>If the function succeeds, the return value is true. If the function fails, the return value is false. To get extended error information, call GetLastError.</returns>
/// <param name="hService">A handle to the service. This handle is returned by the <see cref="OpenService"/> or <see cref="CreateService"/> function. The access rights required for this handle depend on the dwControl code requested.</param>
/// <param name="dwControl">The <see cref="ServiceControl"/> code to send to the service</param>
/// <param name="lpServiceStatus">A pointer to a <see cref="SERVICE_STATUS"/> structure that receives the latest service status information. The information returned reflects the most recent status that the service reported to the service control manager.</param>
/// <returns>If the function succeeds, the return value is true. If the function fails, the return value is false. To get extended error information, call GetLastError.</returns>
/// <param name="hService">A handle to the service. This handle is returned by the <see cref="OpenService"/> or <see cref="CreateService"/> function. The access rights required for this handle depend on the <paramref name="dwControl"/> code requested.</param>
/// <param name="dwControl">The <see cref="ServiceControl"/> code to send to the service</param>
/// <param name="dwInfoLevel">The information level for the service control parameters. This parameter must be set to <see cref="SERVICE_CONTROL_STATUS_REASON_INFO"/></param>
/// <param name="pControlParams">A pointer to the service control parameters. If <paramref name="dwInfoLevel"/> is <see cref="SERVICE_CONTROL_STATUS_REASON_INFO"/>, this member is a pointer to a SERVICE_CONTROL_STATUS_REASON_PARAMS structure.</param>
/// <returns>If the function succeeds, the return value is true. If the function fails, the return value is false. To get extended error information, call GetLastError.</returns>
/// Stops a service using <see cref="ControlService"/> with <see cref="ServiceControl.SERVICE_CONTROL_STOP"/>
/// </summary>
/// <param name="hService">A handle to the service. This handle is returned by the <see cref="OpenService"/> or <see cref="CreateService"/> function. The access rights required for this handle depend on the <paramref name="dwControl"/> code requested.</param>
/// <returns></returns>
publicstaticboolStopService(SC_HANDLEhService)
{
varlpServiceStatus=newSERVICE_STATUS();
returnStopService(hService,reflpServiceStatus);
}
/// <summary>
/// Stops a service using <see cref="ControlService"/> with <see cref="ServiceControl.SERVICE_CONTROL_STOP"/>
/// </summary>
/// <param name="hService">A handle to the service. This handle is returned by the <see cref="OpenService"/> or <see cref="CreateService"/> function. The access rights required for this handle depend on the <paramref name="dwControl"/> code requested.</param>
/// <param name="lpServiceStatus">A pointer to a <see cref="SERVICE_STATUS"/> structure that receives the latest service status information. The information returned reflects the most recent status that the service reported to the service control manager.</param>
/// Stops a service using <see cref="ControlServiceEx"/> with <see cref="ServiceControl.SERVICE_CONTROL_STOP"/>
/// </summary>
/// <param name="hService">A handle to the service. This handle is returned by the <see cref="OpenService"/> or <see cref="CreateService"/> function. The access rights required for this handle depend on the <paramref name="dwControl"/> code requested.</param>
/// <param name="reason">A reason and comment for why the service is being stopped</param>
/// <para>Represents an action that the service control manager can perform.</para>
/// </summary>
/// <remarks>
/// <para>This structure is used by the <see cref="ChangeServiceConfig2"/> and <see cref="QueryServiceConfig2"/> functions, in the SERVICE_FAILURE_ACTIONS structure.</para>
/// The error code the service uses to report an error that occurs when it is starting or stopping. To return an error code
/// specific to the service, the service must set this value to <c>ERROR_SERVICE_SPECIFIC_ERROR</c> to indicate that the
/// <c>dwServiceSpecificExitCode</c> member contains the error code. The service should set this value to <c>NO_ERROR</c> when it
/// is running and on normal termination.
/// </para>
/// </summary>
publicuintdwWin32ExitCode;
/// <summary>
/// <para>
/// A service-specific error code that the service returns when an error occurs while the service is starting or stopping. This
/// value is ignored unless the <c>dwWin32ExitCode</c> member is set to <c>ERROR_SERVICE_SPECIFIC_ERROR</c>.
/// </para>
/// </summary>
publicuintdwServiceSpecificExitCode;
/// <summary>
/// <para>
/// The check-point value the service increments periodically to report its progress during a lengthy start, stop, pause, or
/// continue operation. For example, the service should increment this value as it completes each step of its initialization when
/// it is starting up. The user interface program that invoked the operation on the service uses this value to track the progress
/// of the service during a lengthy operation. This value is not valid and should be zero when the service does not have a start,
/// stop, pause, or continue operation pending.
/// </para>
/// </summary>
publicuintdwCheckPoint;
/// <summary>
/// <para>
/// The estimated time required for a pending start, stop, pause, or continue operation, in milliseconds. Before the specified
/// amount of time has elapsed, the service should make its next call to the SetServiceStatus function with either an incremented
/// <c>dwCheckPoint</c> value or a change in <c>dwCurrentState</c>. If the amount of time specified by <c>dwWaitHint</c> passes,
/// and <c>dwCheckPoint</c> has not been incremented or <c>dwCurrentState</c> has not changed, the service control manager or
/// service control program can assume that an error has occurred and the service should be stopped. However, if the service
/// shares a process with other services, the service control manager cannot terminate the service application because it would
/// have to terminate the other services sharing the process as well.
/// </para>
/// </summary>
publicuintdwWaitHint;
/// <summary>
/// The process identifier of the service.
/// </summary>
publicuintdwProcessId;
/// <summary>
/// This member can be one of the following values.
/// 0 = The service is running in a process that is not a system process, or it is not running. If the service is running in a process that is not a system process, dwProcessId is nonzero.If the service is not running, dwProcessId is zero.
/// 1 = SERVICE_RUNS_IN_SYSTEM_PROCESS The service runs in a system process that must always be running.
/// </summary>
publicuintdwServiceFlags;
}
/// <summary>Provides a handle to a service status handle.</summary>
/// <summary>Required to connect to the service control manager.</summary>
SC_MANAGER_CONNECT=0x0001,
/// <summary>Required to call the CreateService function to create a service object and add it to the database.</summary>
SC_MANAGER_CREATE_SERVICE=0x0002,
/// <summary>
/// Required to call the <see cref="EnumServicesStatus"/> or <see cref="EnumServicesStatusEx"/> function to list the services that are in the database.
/// Required to call the <see cref="NotifyServiceStatusChange"/> function to receive notification when any service is created or deleted.
/// </summary>
SC_MANAGER_ENUMERATE_SERVICE=0x0004,
/// <summary>Required to call the <see cref="LockServiceDatabase"/> function to acquire a lock on the database.</summary>
SC_MANAGER_LOCK=0x0008,
/// <summary>Required to call the <see cref="QueryServiceLockStatus"/> function to retrieve the lock status information for the database.</summary>
SC_MANAGER_QUERY_LOCK_STATUS=0x0010,
/// <summary>Required to call the <see cref="NotifyBootConfigStatus"/> function.</summary>
SC_MANAGER_MODIFY_BOOT_CONFIG=0x0020,
/// <summary>Includes <see cref="ACCESS_MASK.STANDARD_RIGHTS_REQUIRED"/>, in addition to all access rights in this table.</summary>
/// <summary>Required to call the <see cref="QueryServiceConfig"/> and <see cref="QueryServiceConfig2"/> functions to query the service configuration.</summary>
SERVICE_QUERY_CONFIG=0x0001,
/// <summary>Required to call the <see cref="ChangeServiceConfig"/> or <see cref="ChangeServiceConfig2"/> function to change the service configuration. Because this grants the caller the right to change the executable file that the system runs, it should be granted only to administrators.</summary>
SERVICE_CHANGE_CONFIG=0x0002,
/// <summary>
/// Required to call the <see cref="QueryServiceStatus"/> or <see cref="QueryServiceStatusEx"/> function to ask the service control manager about the status of the service.
/// Required to call the <see cref="NotifyServiceStatusChange"/> function to receive notification when a service changes status.
/// </summary>
SERVICE_QUERY_STATUS=0x0004,
/// <summary>
/// Required to call the <see cref="EnumDependentServices"/> function to enumerate all the services dependent on the service.
/// </summary>
SERVICE_ENUMERATE_DEPENDENTS=0x0008,
/// <summary>Required to call the <see cref="StartService"/> function to start the service.</summary>
SERVICE_START=0x0010,
/// <summary>Required to call the <see cref="ControlService"/> function to stop the service.</summary>
SERVICE_STOP=0x0020,
/// <summary>Required to call the <see cref="ControlService"/> function to pause or continue the service.</summary>
SERVICE_PAUSE_CONTINUE=0x0040,
/// <summary>Required to call the <see cref="ControlService"/> function to ask the service to report its status immediately.</summary>
SERVICE_INTERROGATE=0x0080,
/// <summary>Required to call the <see cref="ControlService"/> function to specify a user-defined control code.</summary>
SERVICE_USER_DEFINED_CONTROL=0x0100,
/// <summary>Includes <see cref="ACCESS_MASK.STANDARD_RIGHTS_REQUIRED"/> in addition to all access rights in this table.</summary>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>