首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C# PrincipalContext未找到网络路径

C# PrincipalContext未找到网络路径
EN

Stack Overflow用户
提问于 2014-07-31 13:51:37
回答 1查看 8.4K关注 0票数 2

我试图使用PrincipalContext来检查远程计算机上是否存在本地用户组。

我和PrincipalContext有问题

代码语言:javascript
复制
PrincipalContext ctx = new PrincipalContext(ContextType.Machine, machine, null, ContextOptions.Negotiate)

它适用于以下情况:

  • 局部到局部机器
  • 本地虚拟机
  • 域机到工作组机

然而,它并没有朝着相反的方向工作:

  • 虚拟机到本地主机
  • 工作组机器到域机器

我发现了这些错误:

未处理异常: System.IO.FileNotFoundException:未找到网络路径。未处理异常: System.Runtime.InteropServices.COMException:未找到网络路径。

第一个例外是虚拟机,第二个是工作组机器。

所有机器都有具有相同名称和密码的用户,并且代码是从该用户执行的。

如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-01 07:33:19

我找到了答案。DirectoryServices似乎不能在远程Windows 7或更高版本上工作。我猜当一台计算机在一个工作组中时,它是本地的,我们可以连接,当它在域中时,它是远程的。

我遵循了这里描述的步骤:

System.IO.FileNotFoundException: The network path was not found. Exception while using DirectoryEntry object on 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

但是,我不能更改生产服务器上的服务和注册表设置。我找到了这样的方法来组建团队:

代码语言:javascript
复制
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>();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25060655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档