本文整理汇总了C#中SERVICE_STATUS类的典型用法代码示例。如果您正苦于以下问题:C# SERVICE_STATUS类的具体用法?C# SERVICE_STATUS怎么用?C# SERVICE_STATUS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SERVICE_STATUS类属于命名空间,在下文中一共展示了SERVICE_STATUS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ErrorExit
public static void ErrorExit(ILog log, IntPtr serviceHandle, UInt32 serviceSpecificExitCode)
{
var status = new SERVICE_STATUS
{
dwServiceType = SERVICE_TYPES.SERVICE_WIN32_OWN_PROCESS,
dwCurrentState = SERVICE_STATE.SERVICE_STOPPED,
dwControlsAccepted = 0,
dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR,
dwServiceSpecificExitCode = serviceSpecificExitCode,
dwCheckPoint = 0,
dwWaitHint = 5000,
};
bool serviceStatusRV = SetServiceStatus(serviceHandle, ref status);
log.Debug("SetServiceStatus rv: {0}", serviceStatusRV);
}
示例2: ControlService
public static extern int ControlService( int hService,
uint dwControl,
ref SERVICE_STATUS lpServiceStatus);
示例3: SetServiceStatus
public static extern bool SetServiceStatus(IntPtr hServiceStatus, ref SERVICE_STATUS lpServiceStatus);
示例4: ControlService
public static extern bool ControlService(SafeServiceHandle hService, ServiceControl dwControl, ref SERVICE_STATUS lpServiceStatus);
示例5: StopService
private static void StopService(IntPtr service)
{
SERVICE_STATUS status = new SERVICE_STATUS();
ControlService(service, ServiceControl.Stop, status);
var changedStatus = WaitForServiceStatus(service, ServiceState.StopPending, ServiceState.Stopped);
if (!changedStatus)
throw new ApplicationException("Unable to stop service");
}
示例6: QueryServiceStatus
private static extern int QueryServiceStatus(IntPtr hService, SERVICE_STATUS lpServiceStatus);
示例7: ControlService
private static extern int ControlService(IntPtr hService, ServiceControl dwControl, SERVICE_STATUS lpServiceStatus);
示例8: StartService
private static bool StartService(IntPtr service)
{
SERVICE_STATUS status = new SERVICE_STATUS();
StartService(service, 0, 0);
var changedStatus = WaitForServiceStatus(service, ServiceState.StartPending, ServiceState.Running);
if (!changedStatus)
return false;
return true;
}
示例9: QueryServiceStatus
public static extern bool QueryServiceStatus(
int Service,
ref SERVICE_STATUS ServiceStatus
);
示例10: ControlService
public static extern bool ControlService(
int Service,
SERVICE_CONTROL Control,
ref SERVICE_STATUS ServiceStatus
);
示例11: ControlService
private static extern bool ControlService (
IntPtr hService,
SERVICE_CONTROL_TYPE dwControl,
ref SERVICE_STATUS lpServiceStatus);
示例12: Stop
public override void Stop ()
{
string serviceName = ServiceController.ServiceName;
string machineName = ServiceController.MachineName;
IntPtr scHandle = IntPtr.Zero;
IntPtr svcHandle = IntPtr.Zero;
try {
scHandle = OpenServiceControlManager (machineName,
SERVICE_MANAGER_RIGHTS.SC_MANAGER_CONNECT);
svcHandle = OpenService (scHandle, serviceName, SERVICE_RIGHTS.SERVICE_STOP);
if (svcHandle == IntPtr.Zero)
throw CreateCannotOpenServiceException (serviceName,
machineName);
SERVICE_STATUS status = new SERVICE_STATUS ();
if (!ControlService (svcHandle, SERVICE_CONTROL_TYPE.SERVICE_CONTROL_STOP, ref status))
throw new InvalidOperationException (string.Format (
CultureInfo.CurrentCulture, "Cannot stop {0} service"
+ " on computer '{1}'.", serviceName, machineName),
new Win32Exception ());
} finally {
if (svcHandle != IntPtr.Zero)
CloseServiceHandle (svcHandle);
if (scHandle != IntPtr.Zero)
CloseServiceHandle (scHandle);
}
}
示例13: ExecuteCommand
public override void ExecuteCommand (int command)
{
string serviceName = ServiceController.ServiceName;
string machineName = ServiceController.MachineName;
IntPtr scHandle = IntPtr.Zero;
IntPtr svcHandle = IntPtr.Zero;
try {
scHandle = OpenServiceControlManager (machineName,
SERVICE_MANAGER_RIGHTS.SC_MANAGER_CONNECT);
// MSDN: the hService handle must have the SERVICE_USER_DEFINED_CONTROL
// access right
svcHandle = OpenService (scHandle, serviceName, SERVICE_RIGHTS.SERVICE_USER_DEFINED_CONTROL);
if (svcHandle == IntPtr.Zero)
throw CreateCannotOpenServiceException (serviceName,
machineName);
SERVICE_STATUS status = new SERVICE_STATUS ();
if (!ControlService (svcHandle, (SERVICE_CONTROL_TYPE) command, ref status))
throw new InvalidOperationException (string.Format (
CultureInfo.CurrentCulture, "Cannot control {0} service"
+ " on computer '{1}'.", serviceName, machineName),
new Win32Exception ());
} finally {
if (svcHandle != IntPtr.Zero)
CloseServiceHandle (svcHandle);
if (scHandle != IntPtr.Zero)
CloseServiceHandle (scHandle);
}
}
示例14: SetServiceStatus
public static extern int SetServiceStatus( int hServiceStatus,
ref SERVICE_STATUS lpServiceStatus);
示例15: QueryServiceStatus
public static extern int QueryServiceStatus( int hService,
ref SERVICE_STATUS lpServiceStatus);