首先,一位名叫“ 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服务时,下面的代码无法获取当前登录用户的凭据(用户没有管理员权限,甚至不是我自己)。
using (DirectoryEntry de = new DirectoryEntry("LDAP://MyDomainName"))
{
using (DirectorySearcher adSearch = new DirectorySearcher(de))
{
adSearch.Filter = "(sAMAccountName=" + Environment.UserName + ")";
SearchResult adSearchResult = adSearch.FindOne();
UserInternalEmail = GetProperty(adSearchResult, "mail");
}
}
我被建议在AD / LDAP /域帐户下运行WinService,但这可能是哪个用户?
this.ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.<User ? LocalService ? NetworkService>;
this.ProcessInstaller.Password = "adminpassword";
this.ProcessInstaller.Username = "adminusername";
我的意思是,让我们说一个ABC用户是管理员,让我说我知道这个ABC管理员的密码和用户名,但是当这个管理员更改密码时,我想这会影响我的winservice,它将在70台计算机上运行
有没有办法检索活动目录上的用户凭据?如果您向我提供一些代码示例,我将非常感激。
非常感谢,
答案 0 :(得分:1)
问题是Environment.UserName将始终返回运行服务的服务帐户的用户名,而不是用户登录到该计算机。
有关如何获取登录到工作站的用户名称的信息,请参阅this question。请记住,Windows将允许多个用户同时登录。