Jump to content

howto set wmi object nul in autoit?

Recommended Posts


Taken from here there is a method to set a null variable using wmi objects


ManagementClass mClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection mObjCol = mClass.GetInstances();
foreach (ManagementObject mObj in mObjCol)
  if ((bool)mObj["IPEnabled"])
     ManagementBaseObject mboDNS = mObj.GetMethodParameters("SetDNSServerSearchOrder");
     if (mboDNS != null)
        mboDNS["DNSServerSearchOrder"] = null;
        mObj.InvokeMethod("SetDNSServerSearchOrder", mboDNS, null);

How could I modify the following autoit code to do this?

Local $sNetAdapter = "Ethernet"
Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")

Local $sQueryNetAdapterConfig, $colNetAdapterConfig, $objNetAdapter, $iReturn = 0
Local $adapterName

$adapterName = _GetNetworkAdapterFromID($sNetAdapter)
If $adapterName Then $sNetAdapter = $adapterName

$sQueryNetAdapterConfig = "select * from Win32_NetworkAdapterConfiguration Where Caption like '%" & $sNetAdapter & "'"
ConsoleWrite($sQueryNetAdapterConfig & @CRLF)

$colNetAdapterConfig = $objWMIService.ExecQuery($sQueryNetAdapterConfig, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
ConsoleWrite($colNetAdapterConfig & @CRLF)

Local $aDNSServerSearchOrder[2]
$aDNSServerSearchOrder[0] = ""
$aDNSServerSearchOrder[1] = ""

For $objNetAdapter In $colNetAdapterConfig
ConsoleWrite($objNetAdapter.Description & " Loop " & @CRLF)
$iReturn = $objNetAdapter.SetDNSServerSearchOrder($aDNSServerSearchOrder)
ConsoleWrite($iReturn & @CRLF)


Above code works, but I want the line

$iReturn = $objNetAdapter.SetDNSServerSearchOrder($aDNSServerSearchOrder)

To be something like

$iReturn = $objNetAdapter.SetDNSServerSearchOrder(0)

If that makes sense


Edited by NDog

Share this post

Link to post
Share on other sites

Just use an empty array for example:

#include <Network.au3>

Local $aDNSServerSearchOrder[0]
_SetDNSServerSearchOrder("Ethernet", $aDNSServerSearchOrder)

Assuming from your original functions you're using @jguinch excellent Network UDF.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.