本文介绍了Windows 服务未显示在已安装的服务中(因此无法启动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚构建了一个非常简单的 Windows 服务来测试某些内容并构建它以获取 .exe.根据 MSDN 中的 这篇文章,我还使用Visual Studio 命令提示符 2010(以管理员身份运行)installutil TestService.exe.

当使用 installutil 命令时,一切运行正常,我收到一条消息说服务已安装.此外,为了在我检查服务节点(在 Visual Studio 的服务器资源管理器中)内检查时启动服务,我没有看到任何名为 TestService.exe 的服务.

此外,开始菜单 -> 我的电脑(右键单击)-> 管理 -> 服务和应用程序 -> 服务不显示 TestService.exe,我可以通过它启动服务.>

对如何启动服务有任何建议吗?

OnStart 函数内的代码:

Process[] testProcess = Process.GetProcessesByName("notepad.exe");如果(testProcess.Length == 0)File.WriteAllText(@"C:\Users\User1\Desktop\service.txt", "nothing");别的File.WriteAllText(@"C:\Users\User1\Desktop\service.txt", "运行");
解决方案

我之前在使用 installutil 时遇到过问题,发现使用 sc 命令有效而 installutil 没有.

尝试使用以下命令安装您的服务:

sc create servicename binPath= serviceexe.exe

I just built a very simple Windows service to test something and built it to get the .exe. As per this article in MSDN, I also installed the service using the Visual Studio Command Prompt 2010 (ran as administrator) installutil TestService.exe.

When using the installutil command, everything runs fine and I get a message saying that the service has been installed. Further, to start the service when I check inside the Services node (in Server Explorer in Visual Studio), I do not see any service named TestService.exe.

Also, Start Menu -> My Computer (Right Click) -> Manage -> Services and Application -> Services does not show the TestService.exe through which I could start the service.

Any suggestions how do I start the service?

Code inside OnStart function:

Process[] testProcess = Process.GetProcessesByName("notepad.exe");
if (testProcess.Length == 0)
    File.WriteAllText(@"C:\Users\User1\Desktop\service.txt", "nothing");

else
    File.WriteAllText(@"C:\Users\User1\Desktop\service.txt", "run");
解决方案

I have had problems with installutil before and found using the sc command works whereas installutil didn't.

Try installing your service with this command:

sc create servicename binPath= serviceexe.exe

这篇关于Windows 服务未显示在已安装的服务中(因此无法启动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:35