NDog

howto set wmi object nul in autoit?

2 posts in this topic

#1 ·  Posted (edited)

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

http://stackoverflow.com/questions/5961299/set-dns-to-obtain-automatically-programmatically

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] = "1.1.1.1"
$aDNSServerSearchOrder[1] = "1.1.1.2"

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

Next

Above code works, but I want the line

$iReturn = $objNetAdapter.SetDNSServerSearchOrder($aDNSServerSearchOrder)

To be something like

$iReturn = $objNetAdapter.SetDNSServerSearchOrder(0)

If that makes sense

Thanks

Edited by NDog

Share this post


Link to post
Share on other sites



#2 ·  Posted

Just use an empty array for example:

#RequireAdmin
#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