gpt4 book ai didi

c# - 安装在 Visual Studio 中创建的 Windows 服务

转载 作者:IT王子 更新时间:2023-10-29 03:32:53 25 4
gpt4 key购买 nike

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

我尝试了以下步骤:

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

第 4 步的输出

Running a transacted installation.

Beginning the Install phase of the installation.

See the contents of the log file for the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe assembly's progress.

The file is located at C:\Users\myusername\Documents\Visual Studio 2010\Projects\Tes tService\TestService\obj\x86\Debug\TestService.InstallLog.

Installing assembly 'C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.

Affected parameters are:

logtoconsole =

logfile = C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\T estService\obj\x86\Debug\TestService.InstallLog

assemblypath = C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe

No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe assembly.

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

See the contents of the log file for the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe assembly's progress.

The file is located at C:\Users\myusername\Documents\Visual Studio 2010\Projects\Tes tService\TestService\obj\x86\Debug\TestService.InstallLog.

Committing assembly 'C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.

Affected parameters are:

logtoconsole =

logfile = C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\T estService\obj\x86\Debug\TestService.InstallLog

assemblypath = C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe

No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe assembly.

Remove InstallState file because there are no installers.

The Commit phase completed successfully.

The transacted install has completed.

第 5 步的输出

服务名称无效。

键入 NET HELPMSG 2185 可以获得更多帮助。

最佳答案

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

它不会开箱即用...您需要先创建安装程序类。

关于服务安装程序的一些引用:

How to: Add Installers to Your Service Application

很老...但这就是我所说的:

Windows Services in C#: Adding the Installer (part 3)

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

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

  • serviceProcessInstaller1 具有以下重要属性:Account,即运行服务的帐户。

例如:

this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;

关于c# - 安装在 Visual Studio 中创建的 Windows 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7922105/

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