• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

Executing a method on a WMI object

I've figured out how to access the Win32_NetworkAdapterConfiguration through the WMI to query a few values, but I can't seem to figure out how to execute a method on the object once it comes back in the query.

Specifically, I need to set the EnableStatic method.  Since there are so few objects, this can be a synchronous call if that makes it easier.

This has to be simple, but I just can't get past it.  Probably trying to swallow too much in one night.

Thanks in advance for your help.
0
nhwilly
Asked:
nhwilly
  • 5
  • 4
1 Solution
 
imu79Commented:
Take a look at this MSDN document on executing WMI methods in .NET:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconqueries.asp

hope this helps..
Imran.
0
 
nhwillyAuthor Commented:
Imran,

Nope.  I understand how to do the queries.  I need to execute a method on the object(s) resulting from the query.

I have been all over the MSDN site and I see the reference on how to do it, but there's no meaningful examples, except of queries.

I am trying to change the IP address from DHCP to static. I have seen other posts that modify the registry, but even when I do that, although the registry changes, the IP *at that moment* does not.  I am trying to change the state of the adapter without rebooting.
0
 
imu79Commented:
Sorry - I pasted in the wrong link :(
here's the link which has a couple of examples on how to execute methods on WMI objects:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconexecutingmethodsonmanagementobjects.asp

I hope I've got the link right this time around :-S

let me know if that helps..

I did write some code in VB .NET to execute methods on WMI objects a while back but I can't seem to find it right now. If the link doesn't help much, may be I'll dig in a little more to look for it or else I wont bother much :)

Imran.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
imu79Commented:
Here's a sample code that might work for you:

        Dim oQuery As New SelectQuery("Win32_NetworkAdapterConfiguration")
        Dim oSearch As New ManagementObjectSearcher(oQuery)
        Dim oMgmtObj As ManagementObject
        Dim oArgs As ManagementBaseObject
        Dim oOut As ManagementBaseObject

        For Each oMgmtObj In oSearch.Get()
            If CBool(oMgmtObj("DHCPEnabled")) Then
                oArgs = oMgmtObj.GetMethodParameters("EnableStatic")
                Dim sIPStrings As String() = {"192.168.2.36"}
                oArgs("IPAddress") = sIPStrings
                Dim sSubNetMasks As String() = {"255.255.255.0"}
                oArgs("SubnetMask") = sSubNetMasks
                oOut = oMgmtObj.InvokeMethod("EnableStatic", oArgs, Nothing)
            End If
        Next oMgmtObj

hope this helps..
Imran.
0
 
nhwillyAuthor Commented:
Thanks, I'll try it tonight.  I'm travelling today.
0
 
nhwillyAuthor Commented:
Right on the money!

Well done.

And THANKS!
0
 
imu79Commented:
sure..no problem.

glad to help :)

Imran.
0
 
nhwillyAuthor Commented:
Um...

So, is this thread automatically closed, or is there something else I need to do?  

I don't want to leave it hanging...
0
 
imu79Commented:
I suppose it closes once you've accepted the answer and alloted the points.

so don't worry about it. you should be fine.

Imran.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now