使用 InstallUtil 安装 .NET 服务

发布于 2024-07-04 15:39:54 字数 166 浏览 6 评论 0原文

我正在尝试安装我编写的 .NET 服务。 根据 MSDN 的推荐,我使用 InstallUtil。 但我错过了如何在命令行甚至服务本身中设置默认服务用户。 现在,当运行 InstallUtil 时,它将显示一个对话框,要求用户提供用户的凭据。 我正在尝试将服务安装集成到更大的安装中,并且需要服务安装保持静默。

I'm trying to install a .NET service I wrote. As recommended by MSDN, I'm using InstallUtil. But I have missed how I can set the default service user on the command-line or even in the service itself. Now, when InstallUtil is run, it will display a dialog asking the user for the credentials for a user. I'm trying to integrate the service installation into a larger install and need the service installation to remain silent.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

拥有 2024-07-11 15:39:55

是否要求您提供运行服务的帐户或安装服务的权限? 其次,以管理员身份安装应该可以防止这种情况发生。 首先,您必须将 ServiceProcessInstaller 添加到您的安装程序中。

我相信服务的设计界面有一个创建项目安装程序的链接。 在该设计器上,您可以添加 System.ServiceProcess.ServiceProcessInstaller 类型的流程安装程序。 该对象的属性允许您设置用于服务的帐户。

Are you being asked for the account to run the service under, or for rights to install the service? For the second, installing as admin should prevent that from happening. For the first, you have to add a ServiceProcessInstaller to your Installer.

I believe the design surface for a service has a link to create a Project Installer. On that designer, you can add a process installer of type System.ServiceProcess.ServiceProcessInstaller. The properties of this object allow you to set the account to use for the service.

甜妞爱困 2024-07-11 15:39:55

正如您所注意到的,卡里姆,“帐户”属性就是解决方案,在这里。 对于那些对此属性设置的安全上下文之间的差异感兴趣的人:

http ://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceaccount.aspx

上面使用 InstallUtil 或 SC,我喜欢创建自安装程序的想法:

< a href="http://www.codeproject.com/KB/dotnet/WinSvcSelfInstaller.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/dotnet/WinSvcSelfInstaller.aspx

尽管我在 .Net 1.1 文档中找到了这一点:

ManagedInstallerClass 类型
支持.NET框架
基础设施,并不旨在
直接从您的代码中使用。

As you noticed, Karim, "Account" property is the solution, here. For those interested in differences between security contexts set by this property:

http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceaccount.aspx

Above using InstallUtil or SC, I like the idea of creating a SELF INSTALLER:

http://www.codeproject.com/KB/dotnet/WinSvcSelfInstaller.aspx

even though I found this in the .Net 1.1 documentation:

The ManagedInstallerClass type
supports the .NET Framework
infrastructure and is not intended to
be used directly from your code.

夏日浅笑〃 2024-07-11 15:39:55

另请记住 SC.exe util 它不会需要安装 Visual Studio。 您只需将此 exe 复制到要创建服务的服务器,甚至远程运行即可。 使用obj参数指定用户。

显然这个工具有一个 GUI,但我没有使用过。

Also keep in mind the SC.exe util which does not require visual studio to be installed. You can simply copy this exe to the server you want to create the service or even run it remotely. Use the obj parameter to specify a user.

Apparently there is a GUI for this tool, but I have not used it.

·深蓝 2024-07-11 15:39:55

我想我可能已经找到了。 在服务本身中,自动创建的ServiceProcessInstaller组件有一个属性“Account”,可以设置为“LocalService”、“LocalSystem”、“NetworkService”或“User”。 它默认为“用户”,它必须显示提示。

I think I may have found it. In the service itself, the automatically created ServiceProcessInstaller component has a property "Account" which can be set to "LocalService", "LocalSystem", "NetworkService" or "User". It was defaulting to "User" which must have displayed the prompt.

南风起 2024-07-11 15:39:55

InstallUtil 具有命令行开关,可以避免使用“User”作为帐户类型时出现提示。 /username/password 用于在安装时配置帐户。

用法:

installutil.exe /username=user /password=password yourservice.exe

您可能想要一个配置文件,安装程序可以在其中读取和安装服务。

为此,请将服务安装程序添加到您的项目中,并重载安装方法。 在此方法中,设置用户名和密码:

public override void Install(IDictionary stateSaver)
{
    serviceProcessInstaller1.Username="<username>";
    serviceProcessInstaller1.Password="<password>";
    base.Install(stateSaver);
}

如果您尝试在构造函数中设置用户名和密码,这些值将被覆盖,因此请确保覆盖“Install”来执行此操作。

InstallUtil has command line switches which can avoid the prompts when using "User" as the account type. /username and /password are used configure the account at install time.

Usage:

installutil.exe /username=user /password=password yourservice.exe

What you may want is to have a config file where the installer can read and install the service.

To do so, add a service installer to your project, and overload the install method. In this method, set the username and password:

public override void Install(IDictionary stateSaver)
{
    serviceProcessInstaller1.Username="<username>";
    serviceProcessInstaller1.Password="<password>";
    base.Install(stateSaver);
}

If you try to set the username and password in the constructor, those values will be overwritten, so make sure you override "Install" to do so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文