Windows services 使用Windows服务获取Active Directory当前用户

Windows services 使用Windows服务获取Active Directory当前用户,windows-services,active-directory,Windows Services,Active Directory,首先,一位名叫“leppie”的好心用户试图帮助我,但我找不到我想要的答案,这是一件紧急的事情 我使用LocalSystem帐户在windows 7中运行windows服务(由于此win服务将在多台计算机上远程静默安装,我想我需要使用ServiceInstaller.Designer.cs中的LocalSystem,代码如下: this.ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; th

首先,一位名叫“leppie”的好心用户试图帮助我,但我找不到我想要的答案,这是一件紧急的事情

我使用LocalSystem帐户在windows 7中运行windows服务(由于此win服务将在多台计算机上远程静默安装,我想我需要使用ServiceInstaller.Designer.cs中的LocalSystem,代码如下:

this.ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; 
this.ProcessInstaller.Password = null; 
this.ProcessInstaller.Username = null;
当我运行此windows服务时,下面的代码无法获取当前登录用户的凭据(用户没有管理员权限,甚至我自己也没有)

有人建议我在AD/LDAP/域帐户下运行WinService,但这可能是哪个用户

this.ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.<User ? LocalService ? NetworkService>; 
this.ProcessInstaller.Password = "adminpassword"; 
this.ProcessInstaller.Username = "adminusername";
this.ProcessInstaller.Account=System.ServiceProcess.servicecount。;
this.ProcessInstaller.Password=“adminpassword”;
this.ProcessInstaller.Username=“adminusername”;
我的意思是,假设ABC用户是管理员,假设我知道这个ABC管理员的密码和用户名,但是当这个管理员更改密码时,我想这会影响我的winservice,它将在70台计算机上运行

有没有办法在active directory上检索用户凭据?如果您能提供一些代码示例,我将不胜感激


非常感谢,

问题在于Environment.UserName将始终返回运行服务的服务帐户的用户名,而不是登录计算机的用户的用户名

有关如何获取登录到工作站的用户名称的信息,请参阅。请记住,Windows将允许多个用户同时登录

this.ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.<User ? LocalService ? NetworkService>; 
this.ProcessInstaller.Password = "adminpassword"; 
this.ProcessInstaller.Username = "adminusername";