b***@hotmail.com
2016-02-03 02:16:33 UTC
Phil, you're correct. Thanks for pointing it out. Dns class only provides
domain name resolution capability, so my previous snippet is not bullet
proof if a machine is offline. On XP or above, you may find
Wiin32_PingStatus useful. Here is the snippet I use to ping my machines.
string hostName = "HostNameOrIPAddressHere";
SelectQuery query = new SelectQuery("Win32_PingStatus", "Address='" +
hostName + "'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach(ManagementObject result in searcher.Get())
{
if (null != result["StatusCode"] && (0 ==
(UInt32)result["StatusCode"]))
{
}
else
{
hostName);
}
}
--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
underlying
value is
this
rights.
i must say, THANK YOU FOR THIS WONDERFUL SOLUTIONdomain name resolution capability, so my previous snippet is not bullet
proof if a machine is offline. On XP or above, you may find
Wiin32_PingStatus useful. Here is the snippet I use to ping my machines.
string hostName = "HostNameOrIPAddressHere";
SelectQuery query = new SelectQuery("Win32_PingStatus", "Address='" +
hostName + "'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach(ManagementObject result in searcher.Get())
{
if (null != result["StatusCode"] && (0 ==
(UInt32)result["StatusCode"]))
{
}
else
{
hostName);
}
}
--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
This doesn't actually do a ping, does it? As far as I can tell, this test
will tell you the serverexists even when it's powered off, because it's only validating the name
at a DNS server, notwhether the actual server is up and running.
usedThe ManagementOptions.Timeout property is intended for WMI semi-sync
operations. In particular, the ConnectionOption.Timeout property is not
operations. In particular, the ConnectionOption.Timeout property is not
to control the timeout for a WMI connection. This is because the
WMI COM API doesn't support specifying a timeout value. The timeout
default to the value DCOM specifies (usually 60secs). You can adjust
value via dcomcnfg.exe.
A nicer workaround for the issue is to first ping the server before
...
using System.Net;
string hostName = "ServerNameHere";
bool serverExists = false;
try
{
System.Net.IPHostEntry hostEntry = Dns.GetHostByName(hostName);
serverExists = true;
}
catch(System.Net.Sockets.SocketException)
{
serverExists = false;
}
if (serverExists)
{
}
else
{
}
--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no
A nicer workaround for the issue is to first ping the server before
...
using System.Net;
string hostName = "ServerNameHere";
bool serverExists = false;
try
{
System.Net.IPHostEntry hostEntry = Dns.GetHostByName(hostName);
serverExists = true;
}
catch(System.Net.Sockets.SocketException)
{
serverExists = false;
}
if (serverExists)
{
}
else
{
}
--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
http://www.microsoft.com/info/cpyright.htm
hi all,
i am trying to connect to a machine via WMI and get some info from it.
when i connect to an existing machine, everything goes right. but
when i try to connect to a machine that is not on our network (machine
with such IP does not exist) it takes 30 to 60 seconds to come back
with the error "The RPC server is unavailable." i tried to set
ConnectionOptions.Timeout to something low, but this property does not
seem to have any impact on ManagementScope.connect().
so, i would like to know if it is possible to cut down on the time it
takes for me to figure out that machine with given IP does not exists.
thank you for all your responses.
ManagementScope ms;
ConnectionOptions co;
co = new ConnectionOptions();
co.Username = USERNAME;
co.Password = PASSWD;
co.Timeout = TimeSpan.FromMilliseconds(300);
try
{
ms = new ManagementScope("\\\\10.1.10.110\\root\\cimv2",co);
ms.Connect();
}
catch (COMException COMe)
{
if (COMe.ErrorCode == -2147023174)
// this is where "The RPC server is unavailable." error gets caught
...
...
}
i am trying to connect to a machine via WMI and get some info from it.
when i connect to an existing machine, everything goes right. but
when i try to connect to a machine that is not on our network (machine
with such IP does not exist) it takes 30 to 60 seconds to come back
with the error "The RPC server is unavailable." i tried to set
ConnectionOptions.Timeout to something low, but this property does not
seem to have any impact on ManagementScope.connect().
so, i would like to know if it is possible to cut down on the time it
takes for me to figure out that machine with given IP does not exists.
thank you for all your responses.
ManagementScope ms;
ConnectionOptions co;
co = new ConnectionOptions();
co.Username = USERNAME;
co.Password = PASSWD;
co.Timeout = TimeSpan.FromMilliseconds(300);
try
{
ms = new ManagementScope("\\\\10.1.10.110\\root\\cimv2",co);
ms.Connect();
}
catch (COMException COMe)
{
if (COMe.ErrorCode == -2147023174)
// this is where "The RPC server is unavailable." error gets caught
...
...
}
i tried hard to abort the process in parallel looping... things got dirty
thank you again for this simple solution