Click here to Skip to main content
11,790,613 members (63,809 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WMI

Here is my code.

String dnsServerName = "localhost";
            ManagementScope scope =
               new ManagementScope(@"\\" + dnsServerName + "\\root\\MicrosoftDNS");
            ManagementClass cmiClass =
               new ManagementClass(scope,
                                   new ManagementPath("MicrosoftDNS_AType"),
            ManagementBaseObject inParams =
            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.

Posted 1-May-13 2:05am
Sergey Alexandrovich Kryukov at 1-May-13 10:40am
Not clear what do you mean by referencing a class. What is the problem, exactly?
M.R. Inc at 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.

Sergey Alexandrovich Kryukov at 1-May-13 11:08am
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?
M.R. Inc at 1-May-13 11:11am
Yes, that was referenced successfully but the WmiClass I don't know what to do.

Sergey Alexandrovich Kryukov at 1-May-13 11:13am
What do you men by that? It depends on what you want to do. Does it compile? If not, what's the error?
M.R. Inc at 1-May-13 11:15am
The name 'wmiClass' does not exist in the current context
ganesh.rit at 1-May-13 11:28am
in your case you should use cmiClass instead wmiClass
Sergey Alexandrovich Kryukov at 1-May-13 12:49pm
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.

1 solution

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

Solution 1

wmiClass changed to cmiClass

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

I saw Sergeys name and missed yours

:D Thanks!
richcb at 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 at 1-May-13 11:58am
Well there was no other way to take Ganeshes reply as an answer...
richcb at 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 at 1-May-13 12:01pm
richcb at 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
0 OriginalGriff 1,114
1 Maciej Los 825
2 KrunalRohit 686
3 CPallini 611
4 ppolymorphe 610

Advertise | Privacy | Mobile
Web02 | 2.8.1509028.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2015
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