使用 InstallUtil 安装 .NET 服务
我正在尝试安装我编写的 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是否要求您提供运行服务的帐户或安装服务的权限? 其次,以管理员身份安装应该可以防止这种情况发生。 首先,您必须将 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.
正如您所注意到的,卡里姆,“帐户”属性就是解决方案,在这里。 对于那些对此属性设置的安全上下文之间的差异感兴趣的人:
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 文档中找到了这一点:
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:
另请记住 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.
我想我可能已经找到了。 在服务本身中,自动创建的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.
InstallUtil 具有命令行开关,可以避免使用“User”作为帐户类型时出现提示。
/username
和/password
用于在安装时配置帐户。用法:
您可能想要一个配置文件,安装程序可以在其中读取和安装服务。
为此,请将服务安装程序添加到您的项目中,并重载安装方法。 在此方法中,设置用户名和密码:
如果您尝试在构造函数中设置用户名和密码,这些值将被覆盖,因此请确保覆盖“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:
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:
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.