安装在 Visual Studio 中创建的 Windows 服务 [英] Install Windows Service created in Visual Studio

查看:17
本文介绍了安装在 Visual Studio 中创建的 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Visual Studio 2010 中创建一个新的 Windows 服务时,我收到一条消息,说明使用 InstallUtil 和 net start 来运行该服务.

When I create a new Windows Service in Visual Studio 2010, I get the message stating to use InstallUtil and net start to run the service.

我尝试了以下步骤:

  1. 新建项目文件 -> 新建 -> 项目 -> Windows 服务
  2. 项目名称:TestService
  3. 按原样构建项目(Service1 构造函数、OnStart、OnStop)
  4. 打开命令提示符,运行C:WindowsMicrosoft.NETFrameworkv4.0.30319InstallUtil.exe"TestService.exe
  5. 运行net start TestService.

第 4 步的输出

运行事务安装.

开始安装的安装阶段.

查看日志文件的内容C:用户我的用户名文档Visual Studio2010ProjectsTestServiceTestServiceobjx86DebugTestService.exe大会的进展.

See the contents of the log file for the C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestServiceTestServiceobjx86DebugTestService.exe assembly's progress.

该文件位于 C:UsersmyusernameDocumentsVisual Studio2010项目测试tServiceTestServiceobjx86DebugTestService.InstallLog.

The file is located at C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTes tServiceTestServiceobjx86DebugTestService.InstallLog.

正在安装程序集 'C:UsersmyusernameDocumentsVisual Studio2010ProjectsTestS erviceTestServiceobjx86DebugTestService.exe'.

Installing assembly 'C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestS erviceTestServiceobjx86DebugTestService.exe'.

受影响的参数有:

登录控制台 =

日志文件 = C:UsersmyusernameDocumentsVisual Studio2010项目测试服务TestServiceobjx86DebugTestService.InstallLog

logfile = C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestServiceT estServiceobjx86DebugTestService.InstallLog

assemblypath = C:UsersmyusernameDocumentsVisual Studio2010ProjectsTestServiceTestServiceobjx86DebugTestService.exe

assemblypath = C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestServ iceTestServiceobjx86DebugTestService.exe

没有具有 RunInstallerAttribute.Yes 属性的公共安装程序可以在 C:UsersmyusernameDocumentsVisual Studio 中找到2010ProjectsTestServiceTestServiceobjx86DebugTestService.exe组装.

No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestServiceTestSe rviceobjx86DebugTestService.exe assembly.

Install 阶段成功完成,Commit 阶段是开始.

The Install phase completed successfully, and the Commit phase is beginning.

查看日志文件的内容C:用户我的用户名文档Visual Studio2010ProjectsTestServiceTestServiceobjx86DebugTestService.exe大会的进展.

See the contents of the log file for the C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestServiceTestServiceobjx86DebugTestService.exe assembly's progress.

该文件位于 C:UsersmyusernameDocumentsVisual Studio2010项目测试tServiceTestServiceobjx86DebugTestService.InstallLog.

The file is located at C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTes tServiceTestServiceobjx86DebugTestService.InstallLog.

提交程序集 'C:UsersmyusernameDocumentsVisual Studio2010ProjectsTestS erviceTestServiceobjx86DebugTestService.exe'.

Committing assembly 'C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestS erviceTestServiceobjx86DebugTestService.exe'.

受影响的参数有:

登录控制台 =

日志文件 = C:UsersmyusernameDocumentsVisual Studio2010项目测试服务TestServiceobjx86DebugTestService.InstallLog

logfile = C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestServiceT estServiceobjx86DebugTestService.InstallLog

assemblypath = C:UsersmyusernameDocumentsVisual Studio2010ProjectsTestServiceTestServiceobjx86DebugTestService.exe

assemblypath = C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestServ iceTestServiceobjx86DebugTestService.exe

没有具有 RunInstallerAttribute.Yes 属性的公共安装程序可以在 C:UsersmyusernameDocumentsVisual Studio 中找到2010ProjectsTestServiceTestServiceobjx86DebugTestService.exe组装.

No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:UsersmyusernameDocumentsVisual Studio 2010ProjectsTestServiceTestSe rviceobjx86DebugTestService.exe assembly.

删除 InstallState 文件,因为没有安装程序.

Remove InstallState file because there are no installers.

提交阶段成功完成.

事务安装已完成.

第 5 步的输出

服务名称无效.

输入 NET HELPMSG 2185 可获得更多帮助.

More help is available by typing NET HELPMSG 2185.

推荐答案

您需要在设计器中打开 Service.cs 文件,右键单击它并选择菜单选项添加安装程序".

You need to open the Service.cs file in the designer, right click it and choose the menu-option "Add Installer".

它不会立即安装...您需要先创建安装程序类.

It won't install right out of the box... you need to create the installer class first.

关于服务安装程序的一些参考:

如何:向您的服务添加安装程序申请

很老了……但这就是我要说的:

Quite old... but this is what I am talking about:

Windows 服务C#:添加安装程序(第 3 部分)

通过这样做,将自动创建一个 ProjectInstaller.cs.然后就可以双击这个,进入设计器,配置组件:

By doing this, a ProjectInstaller.cs will be automaticaly created. Then you can double click this, enter the designer, and configure the components:

  • serviceInstaller1 具有服务本身的属性:DescriptionDisplayNameServiceNameStartType 是最重要的.

  • serviceInstaller1 has the properties of the service itself: Description, DisplayName, ServiceName and StartType are the most important.

serviceProcessInstaller1 有一个重要的属性:Account,它是运行服务的帐户.

serviceProcessInstaller1 has this important property: Account that is the account in which the service will run.

例如:

this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;

这篇关于安装在 Visual Studio 中创建的 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆