Discussion:
WMI starts failing with "The RPC server is unavailable" after some
(too old to reply)
Mukesh
2007-02-24 01:41:03 UTC
Permalink
I am trying to connect to servers in my domain and gathering the members of
Administrator group. I have multiple threads calling WMI functions to gather
the administrators. It works fine for some time but starts failing with "RPC
server is unavailable" messages. Soon all the threads report the same
exceptions . I dont get any more results. Anybody seen somthing like this
before?

I am using vs 2003 and .Net 1.1

below is my function which runs with all worker threads.

static void GetAdministratorsInfo()
{
Thread.CurrentThread.Name = Convert.ToString(ThreadNum++);
Thread.CurrentThread.ApartmentState=ApartmentState.MTA;
Console.WriteLine("Starting New Thread with identity: {0}",
Thread.CurrentThread.Name);
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.PacketPrivacy;
co.Authority = "NTLMDOMAIN:MYDOMAIN";
co.Username = LogonAccount;
co.Password = GetAssetOwner.Password;
ManagementScope ms = new ManagementScope();
ManagementPath mp = new ManagementPath();
ObjectQuery oq = new ObjectQuery();
ManagementObjectCollection queryCollection;
oq.QueryLanguage = "WQL";
ManagementObjectSearcher query = new ManagementObjectSearcher();

while (RunNormal)
{
cInHost objOS = null;
inMut.WaitOne();
//Console.WriteLine("Input Mutex held by {0}", Thread.CurrentThread.Name);
if (aIn.Count > 0)
{
objOS = (cInHost)aIn[0];
aIn.RemoveAt(0);
}
inMut.ReleaseMutex();
//Console.WriteLine("Input Mutex Released by {0}",
Thread.CurrentThread.Name);
if (objOS != null)
{
try
{
Console.WriteLine("Thread<{0}>:Trying Hostid <{1}> HostName <{2}>",
Thread.CurrentThread.Name, objOS.HOSTID, objOS.NAME);

string resolvedName = "", osDate = "";
mp.Path = "\\\\" + objOS.NAME + "\\root\\cimv2";
ms.Path = mp ;
ms.Options = co;

//1. Get the Computer Name
oq.QueryString = "Select Name from Win32_ComputerSystem";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
resolvedName = mo["Name"].ToString();
if (resolvedName.Length > 0)
{
break;
}
}
queryCollection.Dispose();
// 2. OS Date
oq.QueryString = "Select * from Win32_OperatingSystem";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
osDate =
ManagementDateTimeConverter.ToDateTime((mo["InstallDate"].ToString())).ToString("yyyy:MM:dd hh:mm:ss.fff");

if (osDate.Length > 0)
{
break;
}
}

queryCollection.Dispose();
// 3. Administrators
oq.QueryString = "Select PartComponent from Win32_GroupUser where
GroupComponent=\"Win32_Group.Domain='" + resolvedName +
"',Name='Administrators'\"";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
string [] strParts = mo["PartComponent"].ToString().Split('=');
string name = strParts[2].Trim('\"');
string domain = strParts[1].Replace(",Name","").Trim('\"');
if (name.Length > 0 && domain.Length > 0)
{
string aOwner = domain + "\\" + name;
outMut.WaitOne();
aOut.Add(new cOutHost(objOS.HOSTID,
objOS.NAME.ToUpper(),resolvedName.ToUpper(), osDate, aOwner));
outMut.ReleaseMutex();
Console.WriteLine("Thread<{0}>: <{1}> identified as owner for HostName
<{2}>", Thread.CurrentThread.Name, aOwner, resolvedName);
}
}
queryCollection.Dispose();


}
catch (Exception e)
{
query.Dispose();
Console.WriteLine("Thread<{0}>: Exception Occured: {1}
",Thread.CurrentThread.Name, e.Message);
Console.WriteLine("Thread<{0}>: Source {1} ",Thread.CurrentThread.Name,
e.Source);
Console.WriteLine("Thread<{0}>: Stack Trace\n {1}
",Thread.CurrentThread.Name, e.StackTrace);
Thread.Sleep(3000);
}
//clear all WMI components
}
else
{
Console.WriteLine("Thread<{0}>: Sleeping", Thread.CurrentThread.Name);
Thread.Sleep(10000);
}
}

}


I get the exception at queryCollection = query.Get();
Mukesh
2007-02-25 23:58:11 UTC
Permalink
I noticed that all the RPC failure occurs after I get this event in my eventlog

Product: Windows Operating System
Event ID: 4226
Source: Tcpip
Version: 5.2
Symbolic Name: EVENT_TCPIP_TCP_CONNECT_LIMIT_REACHED
Message: TCP/IP has reached the security limit imposed on the number of
concurrent (incomplete) TCP connect attempts.

I guess, I need to slow down my application or somehow up the TCP/IP limit.
Any Ideas on how to modify the limit?

-Mukesh Dogra
Post by Mukesh
I am trying to connect to servers in my domain and gathering the members of
Administrator group. I have multiple threads calling WMI functions to gather
the administrators. It works fine for some time but starts failing with "RPC
server is unavailable" messages. Soon all the threads report the same
exceptions . I dont get any more results. Anybody seen somthing like this
before?
I am using vs 2003 and .Net 1.1
below is my function which runs with all worker threads.
static void GetAdministratorsInfo()
{
Thread.CurrentThread.Name = Convert.ToString(ThreadNum++);
Thread.CurrentThread.ApartmentState=ApartmentState.MTA;
Console.WriteLine("Starting New Thread with identity: {0}",
Thread.CurrentThread.Name);
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.PacketPrivacy;
co.Authority = "NTLMDOMAIN:MYDOMAIN";
co.Username = LogonAccount;
co.Password = GetAssetOwner.Password;
ManagementScope ms = new ManagementScope();
ManagementPath mp = new ManagementPath();
ObjectQuery oq = new ObjectQuery();
ManagementObjectCollection queryCollection;
oq.QueryLanguage = "WQL";
ManagementObjectSearcher query = new ManagementObjectSearcher();
while (RunNormal)
{
cInHost objOS = null;
inMut.WaitOne();
//Console.WriteLine("Input Mutex held by {0}", Thread.CurrentThread.Name);
if (aIn.Count > 0)
{
objOS = (cInHost)aIn[0];
aIn.RemoveAt(0);
}
inMut.ReleaseMutex();
//Console.WriteLine("Input Mutex Released by {0}",
Thread.CurrentThread.Name);
if (objOS != null)
{
try
{
Console.WriteLine("Thread<{0}>:Trying Hostid <{1}> HostName <{2}>",
Thread.CurrentThread.Name, objOS.HOSTID, objOS.NAME);
string resolvedName = "", osDate = "";
mp.Path = "\\\\" + objOS.NAME + "\\root\\cimv2";
ms.Path = mp ;
ms.Options = co;
//1. Get the Computer Name
oq.QueryString = "Select Name from Win32_ComputerSystem";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
resolvedName = mo["Name"].ToString();
if (resolvedName.Length > 0)
{
break;
}
}
queryCollection.Dispose();
// 2. OS Date
oq.QueryString = "Select * from Win32_OperatingSystem";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
osDate =
ManagementDateTimeConverter.ToDateTime((mo["InstallDate"].ToString())).ToString("yyyy:MM:dd hh:mm:ss.fff");
if (osDate.Length > 0)
{
break;
}
}
queryCollection.Dispose();
// 3. Administrators
oq.QueryString = "Select PartComponent from Win32_GroupUser where
GroupComponent=\"Win32_Group.Domain='" + resolvedName +
"',Name='Administrators'\"";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
string [] strParts = mo["PartComponent"].ToString().Split('=');
string name = strParts[2].Trim('\"');
string domain = strParts[1].Replace(",Name","").Trim('\"');
if (name.Length > 0 && domain.Length > 0)
{
string aOwner = domain + "\\" + name;
outMut.WaitOne();
aOut.Add(new cOutHost(objOS.HOSTID,
objOS.NAME.ToUpper(),resolvedName.ToUpper(), osDate, aOwner));
outMut.ReleaseMutex();
Console.WriteLine("Thread<{0}>: <{1}> identified as owner for HostName
<{2}>", Thread.CurrentThread.Name, aOwner, resolvedName);
}
}
queryCollection.Dispose();
}
catch (Exception e)
{
query.Dispose();
Console.WriteLine("Thread<{0}>: Exception Occured: {1}
",Thread.CurrentThread.Name, e.Message);
Console.WriteLine("Thread<{0}>: Source {1} ",Thread.CurrentThread.Name,
e.Source);
Console.WriteLine("Thread<{0}>: Stack Trace\n {1}
",Thread.CurrentThread.Name, e.StackTrace);
Thread.Sleep(3000);
}
//clear all WMI components
}
else
{
Console.WriteLine("Thread<{0}>: Sleeping", Thread.CurrentThread.Name);
Thread.Sleep(10000);
}
}
}
I get the exception at queryCollection = query.Get();
Urpiano Cedazo
2007-02-28 09:53:26 UTC
Permalink
http://www.eventid.net/display.asp?eventid=4226&eventno=4252&source=Tcpip&phase=1
--
Un saludo
Fernando Reyes [MS MVP]
MCSE Windows 2000 / 2003
MCSA Windows Server 2003
http://freyes.svetlian.com
http://urpiano.wordpress.com
RSS: http://urpiano.wordpress.com/feed
freyes.champú@champú.mvps.org
(Aclárate la cabeza si quieres escribirme)
Post by Mukesh
I noticed that all the RPC failure occurs after I get this event in my eventlog
Product: Windows Operating System
Event ID: 4226
Source: Tcpip
Version: 5.2
Symbolic Name: EVENT_TCPIP_TCP_CONNECT_LIMIT_REACHED
Message: TCP/IP has reached the security limit imposed on the number of
concurrent (incomplete) TCP connect attempts.
I guess, I need to slow down my application or somehow up the TCP/IP limit.
Any Ideas on how to modify the limit?
-Mukesh Dogra
Post by Mukesh
I am trying to connect to servers in my domain and gathering the members of
Administrator group. I have multiple threads calling WMI functions to gather
the administrators. It works fine for some time but starts failing with "RPC
server is unavailable" messages. Soon all the threads report the same
exceptions . I dont get any more results. Anybody seen somthing like this
before?
I am using vs 2003 and .Net 1.1
below is my function which runs with all worker threads.
static void GetAdministratorsInfo()
{
Thread.CurrentThread.Name = Convert.ToString(ThreadNum++);
Thread.CurrentThread.ApartmentState=ApartmentState.MTA;
Console.WriteLine("Starting New Thread with identity: {0}",
Thread.CurrentThread.Name);
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.PacketPrivacy;
co.Authority = "NTLMDOMAIN:MYDOMAIN";
co.Username = LogonAccount;
co.Password = GetAssetOwner.Password;
ManagementScope ms = new ManagementScope();
ManagementPath mp = new ManagementPath();
ObjectQuery oq = new ObjectQuery();
ManagementObjectCollection queryCollection;
oq.QueryLanguage = "WQL";
ManagementObjectSearcher query = new ManagementObjectSearcher();
while (RunNormal)
{
cInHost objOS = null;
inMut.WaitOne();
//Console.WriteLine("Input Mutex held by {0}",
Thread.CurrentThread.Name);
if (aIn.Count > 0)
{
objOS = (cInHost)aIn[0];
aIn.RemoveAt(0);
}
inMut.ReleaseMutex();
//Console.WriteLine("Input Mutex Released by {0}",
Thread.CurrentThread.Name);
if (objOS != null)
{
try
{
Console.WriteLine("Thread<{0}>:Trying Hostid <{1}> HostName <{2}>",
Thread.CurrentThread.Name, objOS.HOSTID, objOS.NAME);
string resolvedName = "", osDate = "";
mp.Path = "\\\\" + objOS.NAME + "\\root\\cimv2";
ms.Path = mp ;
ms.Options = co;
//1. Get the Computer Name
oq.QueryString = "Select Name from Win32_ComputerSystem";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
resolvedName = mo["Name"].ToString();
if (resolvedName.Length > 0)
{
break;
}
}
queryCollection.Dispose();
// 2. OS Date
oq.QueryString = "Select * from Win32_OperatingSystem";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
osDate =
ManagementDateTimeConverter.ToDateTime((mo["InstallDate"].ToString())).ToString("yyyy:MM:dd
hh:mm:ss.fff");
if (osDate.Length > 0)
{
break;
}
}
queryCollection.Dispose();
// 3. Administrators
oq.QueryString = "Select PartComponent from Win32_GroupUser where
GroupComponent=\"Win32_Group.Domain='" + resolvedName +
"',Name='Administrators'\"";
query.Scope= ms;
query.Query= oq;
queryCollection = query.Get();
query.Dispose();
foreach ( ManagementObject mo in queryCollection)
{
string [] strParts = mo["PartComponent"].ToString().Split('=');
string name = strParts[2].Trim('\"');
string domain = strParts[1].Replace(",Name","").Trim('\"');
if (name.Length > 0 && domain.Length > 0)
{
string aOwner = domain + "\\" + name;
outMut.WaitOne();
aOut.Add(new cOutHost(objOS.HOSTID,
objOS.NAME.ToUpper(),resolvedName.ToUpper(), osDate, aOwner));
outMut.ReleaseMutex();
Console.WriteLine("Thread<{0}>: <{1}> identified as owner for HostName
<{2}>", Thread.CurrentThread.Name, aOwner, resolvedName);
}
}
queryCollection.Dispose();
}
catch (Exception e)
{
query.Dispose();
Console.WriteLine("Thread<{0}>: Exception Occured: {1}
",Thread.CurrentThread.Name, e.Message);
Console.WriteLine("Thread<{0}>: Source {1} ",Thread.CurrentThread.Name,
e.Source);
Console.WriteLine("Thread<{0}>: Stack Trace\n {1}
",Thread.CurrentThread.Name, e.StackTrace);
Thread.Sleep(3000);
}
//clear all WMI components
}
else
{
Console.WriteLine("Thread<{0}>: Sleeping", Thread.CurrentThread.Name);
Thread.Sleep(10000);
}
}
}
I get the exception at queryCollection = query.Get();
Loading...