在 VS2008 中,如何检查 Windows 服务是否在启动条件下运行?
请您参考如下方法:
有关如何检查服务是否在启动条件下运行的详细信息,请参阅 this线程,
The most reliable custom action would be a C++ Dll call inserted before the LaunchConditions action in both UI and Execute sequences.
There's an example of one here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;253683.
Your custom action code can check for the service running and set a property for the LaunchConditions.
您可以使用 ServiceController.GetServices列出本地计算机上运行的服务的方法。
ServiceController[] scServices;
scServices = ServiceController.GetServices();
// Display the list of services currently running on this computer.
Console.WriteLine("Services running on the local computer:");
foreach (ServiceController scTemp in scServices)
{
if (scTemp.Status == ServiceControllerStatus.Running)
{
// Write the service name and the display name
// for each running service.
Console.WriteLine();
Console.WriteLine(" Service : {0}", scTemp.ServiceName);
Console.WriteLine(" Display name: {0}", scTemp.DisplayName);
}
}
