C# 安装后 Windows 服务未出现在服务列表中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1560407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Service not appearing in services list after install
提问by Alex
I've created a windows service in C#, using Visual Studio 2008 I pretty much followed this: http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
我在 C# 中创建了一个 Windows 服务,使用 Visual Studio 2008 我几乎遵循了这个:http: //www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
I created a setup project, as instructed to in the article, and ran it...
it installs my service to C:\Program Files\Product etc....
however, it does not then appear in the services list..
我按照文章中的说明创建了一个安装项目,然后运行它……它安装了我的服务,C:\Program Files\Product etc....
但是它没有出现在服务列表中。
What am I missing?
我错过了什么?
采纳答案by Nate
The most important part of the article you linked, is here
您链接的文章中最重要的部分在这里
To add a custom action to the setup project
1.In Solution Explorer, right-click the setup project, point to View, then choose Custom Actions. The Custom Actions editor appears.
2.In the Custom Actions editor, right-click the Custom Actions node and choose Add Custom Action. The Select Item in Project dialog box appears.
3.Double-click the application folder in the list box to open it, select primary output from MyNewService (Active), and click OK. The primary output is added to all four nodes of the custom actions ? Install, Commit, Rollback, and Uninstall.
4.Build the setup project.
向安装项目添加自定义操作
1.在解决方案资源管理器中,右键单击安装项目,指向查看,然后选择自定义操作。出现自定义操作编辑器。
2.在自定义操作编辑器中,右键单击自定义操作节点并选择添加自定义操作。出现“在项目中选择项目”对话框。
3.双击列表框中的应用程序文件夹打开它,从MyNewService(Active)中选择primary output,然后单击OK。主要输出添加到自定义操作的所有四个节点?安装、提交、回滚和卸载。
4.构建安装项目。
If you skip these steps, your setup project will build and copy your files to the correct directory; however, they will not register your binary as a service without these steps.
如果您跳过这些步骤,您的安装项目将构建并将您的文件复制到正确的目录;但是,如果没有这些步骤,他们不会将您的二进制文件注册为服务。
I should also note that this works for older versions of Visual Studio that had/have the built-in Setup/Deployment project template. The newer versions of Visual Studio have different setup/deployment projects (some requiring third party software.)
我还应该注意,这适用于具有/具有内置安装/部署项目模板的旧版 Visual Studio。较新版本的 Visual Studio 具有不同的安装/部署项目(有些需要第三方软件。)
I'd recommend looking into WiX Toolsetand check here for WiX Installation of Windows Services.
我建议查看WiX 工具集并在此处查看Windows 服务的 WiX 安装。
回答by Jon Seigel
Follow these instructions, they worked for me. For the setup specifically, that part is near the bottom of the article.
按照这些说明,他们为我工作。具体来说,该部分位于文章底部附近。
回答by xofz
I got owned in the face by this one, so I'm putting it here just in case anyone else runs into it.
我被这个人当回事了,所以我把它放在这里以防其他人遇到它。
If you followed the instructions in the guides but are still having issues installing, ensure your Installer class is public. Internal won't work.
如果您按照指南中的说明进行安装但仍有问题,请确保您的安装程序类是公开的。内部不行。
回答by Clarice Bouwer
I had this same issue and then I realized that I never set the parent for the ServiceInstaller.
我遇到了同样的问题,然后我意识到我从未为 ServiceInstaller 设置父级。
Double-click on your project installer. The designer should show a Service Installer and Process Installer. When you click on either and view the properties you should note the Parent attribute which must both be set to the class name of the Project Installer.
双击您的项目安装程序。设计器应显示服务安装程序和流程安装程序。当您单击其中一个并查看属性时,您应该注意 Parent 属性,该属性必须都设置为项目安装程序的类名。
Or, if you do it in code, make sure you set:
或者,如果您在代码中执行此操作,请确保设置:
serviceInstaller.Parent = this;
and
和
serviceProcessInstaller.Parent = this;
回答by Zafar
When installing services, I would highly recommend using NSSM, which worked well for me for all my WinService needs. It can install any executable (even if .bat, .cmd) as a service, and guarantees your service is always up and running.
在安装服务时,我强烈推荐使用NSSM,它非常适合我的所有 WinService 需求。它可以将任何可执行文件(即使是 .bat、.cmd)安装为服务,并保证您的服务始终启动并运行。
To use this tool:
要使用此工具:
Then check the services list, it should be there, up, and running.
然后检查服务列表,它应该在那里,启动并运行。
回答by Dung
In Visual Studio 2013 I ran into the same problem using InstallShield template for service application. But it works like charm when using Setup Project template https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d
在 Visual Studio 2013 中,我将 InstallShield 模板用于服务应用程序时遇到了同样的问题。但是当使用安装项目模板https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d时,它就像魅力一样
so download Setup Project template close your Studio, run this installation and start your Studio, this will work.
所以下载安装项目模板关闭你的工作室,运行这个安装并启动你的工作室,这将工作。
Dunn.
邓恩。
回答by sondlerd
Here is a good tutorial from tgeek001 from CodeProject.com that helped me. It includes several things I didn't see in the posts above: 1. Event handler code to stop the service before uninstalling it 2. Specific conditions and properties in the Custom Actions code to set in order to prevent failures (these fixed the Error 1001 that I experienced while following the instructions in the accepted answer above) 3. Win Service property "Remove Previous Version" dropdown set to true
这是来自 CodeProject.com 的 tgeek001 的一个很好的教程,它帮助了我。它包括我在上面的帖子中没有看到的几件事:1. 在卸载服务之前停止服务的事件处理程序代码 2. 在自定义操作代码中设置的特定条件和属性以防止失败(这些修复了错误 1001我在按照上面接受的答案中的说明进行操作时所经历的) 3. Win 服务属性“删除以前的版本”下拉列表设置为 true
http://www.codeproject.com/Tips/575177/Window-Service-Deployment-using-VS
http://www.codeproject.com/Tips/575177/Window-Service-Deployment-using-VS
The following is from the tutorial for Custom Actions Settings (case matters):
以下来自自定义操作设置教程(案例事项):
- Install, set the Condition property to the following: "NOT (Installed or PREVIOUSVERSIONSINSTALLED)"
- Uninstall, set the Condition property to: "NOT UPGRADINGPRODUCTCODE"
- Commit: set "Custom Action Data" field to: /OldProductCode="[PREVIOUSVERSIONSINSTALLED]"
- 安装,将 Condition 属性设置为以下内容:“NOT (Installed or PREVIOUSVERSIONSINSTALLED)”
- 卸载,将 Condition 属性设置为:“NOT UPGRADINGPRODUCTCODE”
- 提交:将“自定义操作数据”字段设置为:/OldProductCode="[PREVIOUSVERSIONSINSTALLED]"
Lastly, in the WinService project, make sure to set the dropdown "Remove Previous Versions" to true.
最后,在 WinService 项目中,确保将下拉菜单“删除以前的版本”设置为 true。
cheers
干杯
回答by kspearrin
I discovered that your installer class much be in the same project as the Service. The installer cannot exist in a library project referenced by the Service.
我发现您的安装程序类与服务在同一个项目中。安装程序不能存在于服务引用的库项目中。
回答by Sowmiya R
remember to check the name you've given your service before you search. (right click-> properties->check the service name
请记住在搜索之前检查您为服务提供的名称。(右键->属性->检查服务名称