Solved

Executing a method on a WMI object

Posted on 2004-08-25
9
419 Views
Last Modified: 2012-05-05
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
Comment
Question by:nhwilly
  • 5
  • 4
9 Comments
 
LVL 3

Expert Comment

by:imu79
ID: 11902145
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
 

Author Comment

by:nhwilly
ID: 11902669
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
 
LVL 3

Expert Comment

by:imu79
ID: 11902781
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Accepted Solution

by:
imu79 earned 250 total points
ID: 11909405
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
 

Author Comment

by:nhwilly
ID: 11911921
Thanks, I'll try it tonight.  I'm travelling today.
0
 

Author Comment

by:nhwilly
ID: 11935635
Right on the money!

Well done.

And THANKS!
0
 
LVL 3

Expert Comment

by:imu79
ID: 11935727
sure..no problem.

glad to help :)

Imran.
0
 

Author Comment

by:nhwilly
ID: 11936003
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
 
LVL 3

Expert Comment

by:imu79
ID: 11936044
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question