双击启动Windows服务
如何让我的 Windows 服务按以下方式工作...
1.) 安装后自动启动
2.) 即使我们简单地双击可执行文件也会自动启动
换句话说,我不想使用“NET” START”、“SC”命令,并且不想通过服务控制台启动它。我只想让我的服务自动安装并自动启动...加上双击可执行文件时自动启动。
谢谢。
How do I make my Windows Service to work in the following way...
1.) Automatically start after it installs
2.) Automatically start even if we simply double click on the executable
In other words,I dont want to use the "NET START","SC" commands and dont want to start it through the services console. I just want my Service to auto-install and auto start itself...plus start itself automatically when the executable is double clicked.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 ServiceController 类。
您可以在
commited< 中使用它/code>
事件如下:
Have a look at ServiceController class.
You can use it in
commited
event like this :看一下 Topshelf 项目 (http://topshelf-project.com) 并消除所有复杂性在.NET 中编写Windows 服务。它处理所有自注册并消除应用程序对服务代码的所有依赖。
它也是开源的并托管在 GitHub 上,因此可以轻松适应任何应用程序。
(完全披露,我是该项目的作者之一)
Take a look at the Topshelf project (http://topshelf-project.com) and eliminate all the complexity of writing Windows services in .NET. It handles all the self-registration and eliminates all the dependencies on service code from your application.
It's also open-source and hosted on GitHub, making it easy to adapt to any application.
(full disclosure, I am one of the authors on the project)
您可以添加调用安装程序的命令行参数(使用 ManagedInstallerClass.InstallHelper() )以及启动服务的代码...
You can add command line arguments that call the installer ( use
ManagedInstallerClass.InstallHelper()
), and code to start the service...我的帖子在这里< /a> 展示了如何使用
-install
选项让 Windows 服务从命令行自行安装。您可以扩展此逻辑以具有-start
选项,然后在桌面上创建包含该选项的快捷方式。My post here shows how to have your Windows service install itself from the command line using a
-install
option. You could extend this logic to have a-start
option and then create a shortcut on the desktop that includes that option.