I tried the asynchronous call of ManagementOperationObserver and found that RPC is unavailable. I have no time to solve this problem. Please refer to this article for instructions. Thank you.
The Code is as follows:
ConnectionOptions options = new ConnectionOptions ();
Options. Username = "administrator ";
Options. Password = "*********";
ManagementScope Conn = new ManagementScope (@ "\ XXX. XXX \ root \ cimv2", options );
Conn. Connect ();
ObjectQuery query = new ObjectQuery ("select * from win32_PingStatus where Address = 'www .sina.com.cn '");
ManagementObjectSearcher mos =
New ManagementObjectSearcher (Conn, query );
ManagementObjectCollection moc = mos. Get ();
Thread. Sleep (1000 );
Moc = mos. Get ();
String m = "";
Foreach (ManagementObject mo in moc)
{
Object obj = mo. Properties ["StatusCode"]. Value;
If (obj = null)
{
M = "PING failed. The host may be unknown. ";
}
Else
{
If (obj. ToString (). Trim () = "0 ")
{
M = "reply from" + mo. Properties ["Address"]. Value. ToString () + ", in bytes:" +
Mo. Properties ["BufferSize"]. Value. ToString () + ", time:" + mo. Properties ["ResponseTime"]. Value. ToString () +
", TTL:" + mo. Properties ["ResponseTimeToLive"]. Value. ToString ();
Break;
}
}
}
Console. WriteLine (m );