我正在尝试使用 PrimaryContext 来检查远程计算机上是否存在本地用户组。
我遇到问题PrincipalContext
:
PrincipalContext ctx = new PrincipalContext(ContextType.Machine, machine, null, ContextOptions.Negotiate)
它适用于以下场景:
然而,它不适用于相反的方向:
我收到这些错误:
未处理的异常:System.IO.FileNotFoundException:找不到网络路径。
未处理的异常:System.Runtime.InteropServices.COMException:找不到网络路径。
第一个例外是虚拟机,第二个例外是工作组计算机。
所有计算机都有具有相同名称和密码的用户,并且代码是从该用户执行的。
如何解决这个问题?
我找到了答案。 DirectoryServices 似乎无法在远程 Windows 7 或更高版本上运行。
我想当一台计算机位于工作组中时,它就是本地计算机,我们可以连接;当它位于域中时,它就是远程计算机。
我按照此处描述的步骤进行操作:
System.IO.FileNotFoundException:找不到网络路径。在 Windows 7 上使用 DirectoryEntry 对象时出现异常 https://stackoverflow.com/questions/13955880/system-io-filenotfoundexception-the-network-path-was-not-found-exception-while
和这里:
http://www.peppercrew.nl/index.php/2011/09/connect-to-remote-registry-fails-with-an-error-is-preventing-this-key-from-being-opened/ 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>();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)