如何在没有 InstallUtil.exe vb.net 的情况下安装 .NET Windows 服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9069812/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:12:29  来源:igfitidea点击:

How to install a .NET windows service without InstallUtil.exe vb.net

.netvb.netservicewindows-servicesinstallutil

提问by Simon

I have created a windows service in vb.net. Is there anyway i can create an installation for it that does not require installutil to be used?

我在 vb.net 中创建了一个 Windows 服务。无论如何,我可以为它创建一个不需要使用 installutil 的安装吗?

回答by David

Installutil is necessary, but to make things easier, you can create a Setup project, so that you simply run an .msi to install the service. (This uses installutil under the hood, but it greatly simplifies installation.)

Installutil 是必要的,但为了简化操作,您可以创建一个安装项目,以便您只需运行 .msi 来安装服务。(这在幕后使用了 installutil,但它极大地简化了安装。)

One walkthrough is here: http://support.microsoft.com/kb/816169

一个演练在这里:http: //support.microsoft.com/kb/816169

And another is here: http://msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx

另一个在这里:http: //msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx

The main difference between the two is the amount of code in the samples. They both walk you throuigh the same process.

两者之间的主要区别在于示例中的代码量。他们都会引导您完成相同的过程。

The articles linked to are old, but still apply in VS2010. I used the second article to walk through the process for a VS2010 service just last week.

链接的文章是旧的,但仍然适用于 VS2010。上周,我使用第二篇文章介绍了 VS2010 服务的流程。

回答by jglouie

Why do you want to avoid installutils?

为什么要避免 installutils?

You could try using the sccommand, as in sc create ...

您可以尝试使用该sc命令,如sc create ...

EDIT: Here's an MSDN page for it: http://support.microsoft.com/?kbid=251192

编辑:这是它的 MSDN 页面:http: //support.microsoft.com/?kbid=251192

DESCRIPTION:
        Creates a service entry in the registry and Service Database.
USAGE:
        sc <server> create [service name] [binPath= ] <option1> <option2>...

OPTIONS:
NOTE: The option name includes the equal sign.
      A space is required between the equal sign and the value.
 type= <own|share|interact|kernel|filesys|rec>
       (default = own)
 start= <boot|system|auto|demand|disabled|delayed-auto>
       (default = demand)
 error= <normal|severe|critical|ignore>
       (default = normal)
 binPath= <BinaryPathName>
 group= <LoadOrderGroup>
 tag= <yes|no>
 depend= <Dependencies(separated by / (forward slash))>
 obj= <AccountName|ObjectName>
       (default = LocalSystem)
 DisplayName= <display name>
 password= <password>

回答by Robert Beaubien

You can always do it with registry entries.
The keys are found in HKLM\SYSTEM\CurrentControlSet\services

您始终可以使用注册表项来执行此操作。
钥匙位于HKLM\SYSTEM\CurrentControlSet\services

The key name you create is the embedded name of the service on your service handler. The following values are relevant:

您创建的键名称是服务处理程序中服务的嵌入名称。以下值是相关的:

DisplayName= text that gets displayed in the services manager

DisplayName= 显示在服务管理器中的文本

ImagePath= FQ Filename of service executable

ImagePath= 服务可执行文件的 FQ 文件名

Start(DWORD) = startup type (3 = autostart)

Start(DWORD) = 启动类型 (3 = 自动启动)

DelayedAutoStart(DWORD) = (1 = delayed)

DelayedAutoStart(DWORD) = (1 = 延迟)

WOW64(DWORD) = (0 = 64-bit app, 1 = 32-bit app)

WOW64(DWORD) = (0 = 64 位应用程序,1 = 32 位应用程序)

ErrorControl(DWORD) = 0

ErrorControl(双字)= 0

ObjectName= {username} to run under (LocalSystem for system account)

ObjectName= {username} 下运行(本地系统为系统帐户)

There are lots of other values, but that should get you started.

还有很多其他值,但这应该会让你开始。