使用wmi连接远程机子的时候为什么提示“RPC服务器不可用”?
尝试连接局域网是可以的。
但是远程却不行。不知道是什么原因?
rpc服务是开着的。
是不是编程的时候还需要注意什么呢?
public string IsHostConnection(string hostname,string username,string password)
{
ConnectionOptions options=new ConnectionOptions();
options.Username=username;
options.Password=password;
ManagementScope ms=new ManagementScope("\\\\" +hostname+ "\\root\\cimv2",options);
//ManagementScope ms=new ManagementScope("\\\\.\\root\\cimv2",options);
try
{
ms.Connect();
}
catch(Exception e)
{
return e.Message;
}
if (ms.IsConnected)
{
return "Success!";
}
else
{
return "False...";
}
}
private void button1_Click(object sender, System.EventArgs e)
{
string message=IsHostConnection(hostname.Text,username.Text,password.Text);
MessageBox.Show(message);
}