Solved

Executing a method on a WMI object

Posted on 2004-08-25
9
420 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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