Click here to Skip to main content
12,295,482 members (53,520 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# WMI
Hello

Here is my code.

String dnsServerName = "localhost";
            ManagementScope scope =
               new ManagementScope(@"\\" + dnsServerName + "\\root\\MicrosoftDNS");
 
            scope.Connect();
 
            ManagementClass cmiClass =
               new ManagementClass(scope,
                                   new ManagementPath("MicrosoftDNS_AType"),
                                   null);
 
            ManagementBaseObject inParams =
                wmiClass.GetMethodParameters("CreateInstanceFromPropertyData");
 
            inParams["DnsServerName"] = this.ServerName;
            inParams["ContainerName"] = zone;
            inParams["OwnerName"] = hostName + "." + zone;
            inParams["IPAddress"] = iPAddress;
 
            cmiClass.InvokeMethod("CreateInstanceFromPropertyData", inParams, null);

I was able to reference 'ManagementClass' successfully.

But I have googled and googled but I don't understand how to reference wmiClass correctly.

Please can some one help me.

Thanks
Posted 1-May-13 2:05am
M.R. Inc1.1K
Comments
   
Not clear what do you mean by referencing a class. What is the problem, exactly?
—SA
M.R. Inc 1-May-13 10:46am
   
In C# you reference DLLs so that you can control certain aspects of the computer.

Like you would reference a DLL to change windows colours.

In my case.

I do not understand what to do to reference WmiClass so that I can control my DNS server.

Thanks
   
OK, you demonstrated that you poorly understand what is referencing the DLL, thank you. Essentially, you reference assembly, no "DLL", which is meaningful in .NET (just a file type). What is "reference a class"? OK, did you add the System.Management reference?
—SA
M.R. Inc 1-May-13 11:11am
   
Yes, that was referenced successfully but the WmiClass I don't know what to do.

Thanks
   
What do you men by that? It depends on what you want to do. Does it compile? If not, what's the error?
—SA
M.R. Inc 1-May-13 11:15am
   
Error
The name 'wmiClass' does not exist in the current context
ganesh.rit 1-May-13 11:28am
   
in your case you should use cmiClass instead wmiClass
   
This is because you declare "wmiClass" and spelled "cmiClass" below. Come on, Visual Studio points it out precisely. You need to learn how to read it. And please, read the chapter on .NET assemblies. This is one of the most fundamental things.
—SA

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

wmiClass changed to cmiClass

Thank you Sergey and Ganesh!! Smile | :)
  Permalink  
v2
Comments
ganesh.rit 1-May-13 11:32am
   
Wonder in this world ..... Ganesh answers the question and Sergey gets thank you :P
M.R. Inc 1-May-13 11:36am
   
Sorry mate!!

I saw Sergeys name and missed yours

:D Thanks!
richcb 1-May-13 11:38am
   
Why did you post a comment as a solution to your own question? Be careful not to do that as it can be construed as abuse.
M.R. Inc 1-May-13 11:58am
   
Well there was no other way to take Ganeshes reply as an answer...
richcb 1-May-13 12:00pm
   
I understand. I just wanted to give you a heads up so you would avoid being reported as an abuser in the future.
M.R. Inc 1-May-13 12:01pm
   
Thanks!
richcb 1-May-13 12:02pm
   
No problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100