安装windows服务发生异常

安装windows服务发生异常  

报错如下:

在“安装”阶段发生异常。
System.ComponentModel.Win32Exception: 帐户名无效或不存在,或者密码对于指定的帐户名无效。

解决方法:

1 serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

设置serviceProcessInstaller的Account属性为LocalSystem

2 当serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User; 时

在输入用户名、密码时注意用户名的形式为 机器名用户名