Click here to Skip to main content
Rate this: bad
good
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 3:05am
Comments
Sergey Alexandrovich Kryukov at 1-May-13 10:40am
   
Not clear what do you mean by referencing a class. What is the problem, exactly?
—SA
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.
 
Thanks
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?
—SA
M.R. Inc at 1-May-13 11:11am
   
Yes, that was referenced successfully but the WmiClass I don't know what to do.
 
Thanks
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?
—SA
M.R. Inc at 1-May-13 11:15am
   
Error
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.
—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 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
   
Thanks!
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 Maciej Los 295
1 OriginalGriff 249
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 197
4 Sinisa Hajnal 176
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2014
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