Solved

Executing a method on a WMI object

Posted on 2004-08-25
9
417 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 3

Accepted Solution

by:
imu79 earned 250 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Author Comment

by:nhwilly
Comment Utility
Right on the money!

Well done.

And THANKS!
0
 
LVL 3

Expert Comment

by:imu79
Comment Utility
sure..no problem.

glad to help :)

Imran.
0
 

Author Comment

by:nhwilly
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now