c#程序 DirectoryEntry类的一个问题,大哥们帮帮忙啊!

yeawei 2012-09-23 05:25:02
DirectoryEntry de = new DirectoryEntry(@"IIS://" + this.MachineName + @"/W3SVC", this.LoginAccount, this.LoginPassword);

当this.MachineName为本机即localhost的时候能够正常连接。

当this.MachineName为远程机器的IP时,若账号密码错误,就报:拒绝访问。这个没问题。

但是当账号密码正确的时候,就报:RPC 服务器不可用。有没有哪位大神碰到过并解决过这个问题的啊?PS:远程机器的RPC服务已开启

小弟在此先谢过各位了!
...全文
225 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yeawei 2012-09-24
  • 打赏
  • 举报
回复
防火墙关了还是不行,RPC已经开启了的。。。
yeawei 2012-09-24
  • 打赏
  • 举报
回复
麻烦哪位大大帮忙测试下啊,127.0.0.1肯定是可以的,换成远程就不行了。。。

VS需要用管理员权限运行才能调试的!
yeawei 2012-09-24
  • 打赏
  • 举报
回复
static void Main(string[] args)
{
string MachineName = "127.0.0.1";

string LoginAccount = "username";

string LoginPassword = "password";

DirectoryEntry rootDirectory = new DirectoryEntry(@"IIS://" + MachineName + @"/W3SVC", LoginAccount, LoginPassword);
int totalServerCount = 0;
try
{

foreach (DirectoryEntry child in rootDirectory.Children)
{
if (child.SchemaClassName == "IIsWebServer")
{
totalServerCount++;
}
}
}
catch (Exception ex)
{
throw (new Exception("Can't connect to IIS Server " + MachineName + " : " + ex.Message));
}

Console.WriteLine(totalServerCount);



这是一段控制台测试程序,放入Program.cs的main方法中即可,需要引入System.DirectoryServices;
宝_爸 2012-09-24
  • 打赏
  • 举报
回复

防火墙关闭试试

  • 打赏
  • 举报
回复
先不要通过程序,直接在网上邻居中看看能不能打开这个目录,如果打不开共享,防火墙都看一下

如果再不行,RPC(Remote Procedure Call Protocol)——远程过程调用协议
看看远程的这个协议有没有
yeawei 2012-09-24
  • 打赏
  • 举报
回复
哎。。。

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧