Wmi help

B

blazerguns

Hi all,

Iam new to using wmi methods. I tried to enable wins using
wmi. The code is below.

public void EnableWinsServer()
{
ManagementClass objMC = new
ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();

foreach (ManagementObject objMO in objMOC)
{
if (!(bool)objMO["IPEnabled"])
continue;
ManagementBaseObject NewobjWins = null;
ManagementBaseObject SetobjWins = null;
NewobjWins = objMO.GetMethodParameters("EnableWINS");
NewobjWins["DNSEnabledForWINSResolution"] =
(bool)false;
NewobjWins["WINSEnableLMHostsLookup"] = (bool)true;

SetobjWins = objMO.InvokeMethod("EnableWINS",
NewobjWins, null);
}

}

Iam getting an exception on InvokeMethod("EnableWINS"....).
It says "Invalid Method". may be iam wrong but can someone correct me
how to go about it.
Its urgent.

Another doubt is how can i use wmi method to find out if the dns server
ips are got from dhcp or from user manual entry?

Varun
 
W

Willy Denoyette [MVP]

| Hi all,
|
| Iam new to using wmi methods. I tried to enable wins using
| wmi. The code is below.
|
| public void EnableWinsServer()
| {
| ManagementClass objMC = new
| ManagementClass("Win32_NetworkAdapterConfiguration");
| ManagementObjectCollection objMOC = objMC.GetInstances();
|
| foreach (ManagementObject objMO in objMOC)
| {
| if (!(bool)objMO["IPEnabled"])
| continue;
| ManagementBaseObject NewobjWins = null;
| ManagementBaseObject SetobjWins = null;
| NewobjWins = objMO.GetMethodParameters("EnableWINS");
| NewobjWins["DNSEnabledForWINSResolution"] =
| (bool)false;
| NewobjWins["WINSEnableLMHostsLookup"] = (bool)true;
|
| SetobjWins = objMO.InvokeMethod("EnableWINS",
| NewobjWins, null);
| }
|
| }
|
| Iam getting an exception on InvokeMethod("EnableWINS"....).
| It says "Invalid Method". may be iam wrong but can someone correct me
| how to go about it.
| Its urgent.
|
| Another doubt is how can i use wmi method to find out if the dns server
| ips are got from dhcp or from user manual entry?
|
| Varun
|

You need to call methods on a Class not on an instance.

if(...)
continue;
ManagementClass mc = new ManagementClass(objMO .ClassPath);
..
mc.GetMethodParameters(...);
..
mc.InvokeMethod(...);

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top