安装.NET开发的Windows服务时出错
我使用 C# 和 Visual Studio 2008 开发了一个 Windows 服务。我的计算机上安装了 Windows XP SP2。当我尝试使用 installutil 工具安装服务时,输入用户名和密码后,出现以下错误。
安装阶段发生异常。 System.ComponentModel.Win32Exception:帐户名无效或不存在,或者指定帐户名的密码无效。
但用户确实存在。我通过控制面板→用户帐户→创建新帐户创建了用户。
我用于安装服务的命令是:
installutil /i TestService.exe
如何解决该问题?
I have developed a windows service using C# and Visual Studio 2008. I have Windows XP SP2 installed on my machine. When I try to install the service using the installutil tool, after entering the username and password, I get the following error.
An exception occurred during the Install phase.
System.ComponentModel.Win32Exception: The account name is invalid or does not exist, or the password is invalid for the account name specified.
But the user does exist. I had created the user through control panel → User accounts → Create new account.
The command I used for installing the service was:
installutil /i TestService.exe
How can I resolve the issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果该帐户是本地用户帐户,请在 installutil 提示输入用户名和密码时尝试使用
.\username
。.\
代表本地计算机。服务需要完全限定的用户名(带有域),因此在安装时您需要明确本地用户帐户。
If the account is a local user account, try to use
.\username
when installutil prompts for the username and password.The
.\
stands for local machine.Services require a fully qualified username (with domain), so when installing you need to be explicit about local user accounts.
该帐户可能还需要被授予“作为服务登录”帐户权限;将
SE_SERVICE_LOGON_NAME
常量传递给LsaAddAccountRights()
API。The account may also need to be given the "Log on as a service" account right; pass the
SE_SERVICE_LOGON_NAME
constant to theLsaAddAccountRights()
API.我通过将 ServiceProcessInstaller.Account 更改为 LocalSystem 解决了这个问题,它对我有用。
I solved this by changing ServiceProcessInstaller.Account to LocalSystem, and it works for me.