473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting 'Generic failure' error in ManagementClass.GetInstances()

I am getting following error while iterating through the ManagementObjectCollection:
This error is coming only for the first time. From the 2nd run onwards the code is executed successfully. Surprisingly when I execute the code with the gap of 20-25 minutes the error is reproducible!

Please provide the solution urgently.

Thanks in Advance !

Please check the error details, sample C# code I am using.

Regards,

Sachin R.
================================================== ==
Expand|Select|Wrap|Line Numbers
  1. Error Details: 
  2.  
  3. ManagementException Error: Generic failure
  4. ManagementException Error code: Failed
  5. ManagementException ErrorInformation: System.Management.ManagementBaseObject
  6. ManagementException Error:    at System.Management.ManagementException.ThrowWith
  7. ExtendedInfo(ManagementStatus errorCode)
  8.    at System.Management.ManagementObjectEnumerator.MoveNext()
  9.    at TestWMI.Class2.Main(String[] args)
  10.  
================================================== ========
C# Code:
Description: Using following C# code: Problematic code line is marked in bold tag.

Expand|Select|Wrap|Line Numbers
  1.             try 
  2.             {
  3.                 string machineName = "dnsMachineName";
  4.                 System.Net.IPHostEntry iphe = System.Net.Dns.Resolve(machineName);
  5.                 string DnsServerName = iphe.HostName;
  6.                 string NameSpace = "\\\\" + DnsServerName + "\\root\\MicrosoftDNS";
  7.                 System.Management.ManagementScope EManagementScope = new System.Management.ManagementScope( NameSpace);
  8.                 EManagementScope.Connect();
  9.                 ManagementPath EZonePath = new ManagementPath("\\root\\MicrosoftDNS:MicrosoftDNS_Zone");
  10.                 ObjectGetOptions EGetOptions = new ObjectGetOptions();
  11.                 ManagementClass EManagementClass = new ManagementClass(EManagementScope , EZonePath, EGetOptions);
  12.                 ManagementObjectCollection mgmObjcoll =  EManagementClass.GetInstances();
  13.                 foreach (ManagementObject MyZoneObj in EManagementClass.GetInstances())                  {
  14.                     Console.WriteLine(MyZoneObj.Path);
  15.                     break;
  16.                 }
  17.             }
  18.             catch(ManagementException ex) 
  19.             {
  20.                 Console.WriteLine("ManagementException Error: "+ex.Message);
  21.                 Console.WriteLine("ManagementException Error code: "+ex.ErrorCode);
  22.                 Console.WriteLine("ManagementException ErrorInformation: "+ex.ErrorInformation);
  23.                 Console.WriteLine("ManagementException Error: "+ex.StackTrace);
  24.             }
Apr 2 '07 #1
0 2147

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ryan Berry | last post by:
Hi there, We have created a custom adapter for Microsoft BizTalk using C#. We wish to add the adapter to the BizTalk adapters list automatically upon install and remove it on uninstall. We...
0
by: PRM | last post by:
Hi I am sharing a network drive, by using the following code (C# Code using ASP.net /********************************************************************************** public void ShareMap(string...
24
by: anders | last post by:
Hi! Im trying to add a A record to a domain name in MS DNS with C#, it's done from a webpage with this code: ManagementClass rr = new ManagementClass(@"root\MicrosoftDNS",...
4
by: Steve Teeples | last post by:
I am calling the method GetInstances() within the ManagementClass. I have 48 applications on my system. Mearly calling the routine takes 28 seconds for it to return. I don't understand why this...
3
by: Mark Prenter | last post by:
Hello, I'm trying to find a way to retrieve the MAC address from a network card in a Visual C++ .NET managed application. I've found some examples in C#, but I just can't get them to work in C++....
1
by: lecnac | last post by:
Here's some details: Server and workstation both in the same workgroup Logged into server as local Administrator Logged into workstation as a local user that is only in the Users group The...
1
by: lecnac | last post by:
Sorry for the repost. I must have done something wrong when I tried to post my reply (I can't seem to find it). Anyway, I'd really appreciate any help that anyone could provide. My issue is...
2
by: =?Utf-8?B?Qy4gSHVnaGVz?= | last post by:
Hi, I can't figure it out. A piece of code to obtain the Processor ID which has always worked fine, suddenly throws an UnauthorizedAccessException. I have changed absolutely nothing to my code,...
1
by: Pioneer | last post by:
Hi, I need to get MAC address/physical ip address of machine. I am using below code: ManagementClass mc = new ManagementClass("Win32_NetworkAdapter"); foreach (ManagementObject mo in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.