Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Executing a method on a WMI object

Posted on 2004-08-25
9
Medium Priority
?
424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
LVL 3

Accepted Solution

by:
imu79 earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 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