• TimeOut for ManagementScope.connect()

    From pkhalili498@gmail.com@21:1/5 to All on Wed Jan 16 07:57:43 2019
    در سه‌شنبه 9 ژوئیهٔ 2002، ساعت 1:30:27 (UTC+4:30)، Andy Cheung [MS] نوشته:
    The ManagementOptions.Timeout property is intended for WMI semi-sync operations. In particular, the ConnectionOption.Timeout property is not used to control the timeout for a WMI connection. This is because the underlying WMI COM API doesn't support specifying a timeout value. The timeout value is default to the value DCOM specifies (usually 60secs). You can adjust this value via dcomcnfg.exe.

    A nicer workaround for the issue is to first ping the server before attempting to make a WMI connection to it. Here is a possible code:

    ...
    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)
    {
    Console.WriteLine(@"\\{0} machine exists", hostName);
    }
    else
    {
    Console.WriteLine(@"\\{0} machine does not exist", 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


    "Arkady N." <arkan@iname.com> wrote in message news:8650b20e.0207081021.7b914d09@posting.google.com...
    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.

    below is a piece of code that i am executing (in C#) :



    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
    ...
    ...
    }

    Hi,
    I have the same issue,I find that my Server Provider has closed ICMP port so I can not ping the server.
    is this the problem of "RPC server is not Available"?
    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)