我试图使用PrincipalContext来检查远程计算机上是否存在本地用户组。
我和PrincipalContext有问题
PrincipalContext ctx = new PrincipalContext(ContextType.Machine, machine, null, ContextOptions.Negotiate)它适用于以下情况:
然而,它并没有朝着相反的方向工作:
我发现了这些错误:
未处理异常: System.IO.FileNotFoundException:未找到网络路径。未处理异常: System.Runtime.InteropServices.COMException:未找到网络路径。
第一个例外是虚拟机,第二个是工作组机器。
所有机器都有具有相同名称和密码的用户,并且代码是从该用户执行的。
如何解决这个问题?
发布于 2014-08-01 07:33:19
我找到了答案。DirectoryServices似乎不能在远程Windows 7或更高版本上工作。我猜当一台计算机在一个工作组中时,它是本地的,我们可以连接,当它在域中时,它是远程的。
我遵循了这里描述的步骤:
在这里:
http://www.peppercrew.nl/index.php/2011/09/connect-to-remote-registry-fails-with-an-error-is-preventing-this-key-from-being-opened/
Enable File and Print sharing in the Firewall
Start the Remote Registry Service
Add remote user access to this registry entry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg
但是,我不能更改生产服务器上的服务和注册表设置。我找到了这样的方法来组建团队:
var server = new DirectoryEntry(string.Format("WinNT://{0},Computer", machine));
DirectoryEntry group = server.Children.Cast<DirectoryEntry>().Where(
d => d.SchemaClassName.Equals("Group") && d.Name.Equals("Administrators")
).Single<DirectoryEntry>();https://stackoverflow.com/questions/25060655
复制相似问题