Wmi help

  • Thread starter Thread starter blazerguns
  • Start date Start date
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
 
| 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.
 
Back
Top