Windows服务在安装时选择用户或系统帐户

Ada*_*amC 17 .net c# windows-services

安装Windows服务时,有没有办法让用户安装在特定用户帐户和计算机帐户之间进行选择,例如LocalSystem?我看到如何通过服务安装程序属性在构建时执行此操作,但在安装期间不这样做.

Bad*_*pot 29

@Doobi,@ Eric,根据我的经验(Win7Home 64位,VS2010Express,不在域上)

 processInstaller.Account = ServiceAccount.LocalService;
 processInstaller.Username = null;
 processInstaller.Password = null;
Run Code Online (Sandbox Code Playgroud)

将在没有密码提示的情况下将服务安装为LocalService.

要将服务安装为本地用户帐户(并提供密码提示以使用户能够提供凭据),我必须使用:

 this.serviceProcessInstaller.Account =System.ServiceProcess.ServiceAccount.User;
 this.serviceProcessInstaller.Password = null;
 this.serviceProcessInstaller.Username = null;
Run Code Online (Sandbox Code Playgroud)

我必须采取的安装服务的重要步骤是将计算机名称放在凭证对话框中,即MYPC\dave代替dave.我很惊讶我必须这样做,因为它不在域上.我添加了这条评论,因为没有其他帖子我看过这个提及必须在用户名前加上PC名称.

  • 感谢computername\username提示修复了我的问题 (2认同)

Doo*_*obi 6

是的,这是在流程安装程序上.我认为在较新的框架中,如果您在设计图面上选择流程安装程序,则它是一个可见属性.我最后一次(.net 2.0)你必须在*.designer.cs文件中添加类似的内容:

 processInstaller.Account = ServiceAccount.LocalService;
 processInstaller.Username = null;
 processInstaller.Password = null;
Run Code Online (Sandbox Code Playgroud)

  • @Doobi,根据您的评论,您是否更需要这行代码?`processInstaller.Account = ServiceAccount.User;` (2认同)