gpt4 book ai didi

c# - 启动条件 - 检查服务是否正在运行

转载 作者:太空宇宙 更新时间:2023-11-03 22:22:12 26 4
gpt4 key购买 nike

在 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);
}
}

关于c# - 启动条件 - 检查服务是否正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2686227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com