title: Problems in setting DNS address
body: <p>I'm using one popular Delphi function and one laptop with Wi-fi adapter connected on attempt to set preferred and alternative dns server address and catch an error saying - "Invalid Syntax". I think "Win32_NetworkAdapterConfiguration" function work only in Ethernet adapters and not in Wi-fi adapters, or I'm wrong? </p>
  
  <p>Exceptions generated:</p>
  
  <p><a href="http://prntscr.com/4qvjmz" rel="nofollow noreferrer">http://prntscr.com/4qvjmz</a>
  <img src="https://i.stack.imgur.com/orKdL.png" alt="enter image description here">
  <a href="http://prntscr.com/4qvjvn" rel="nofollow noreferrer">http://prntscr.com/4qvjvn</a><br>
  <img src="https://i.stack.imgur.com/qtl9U.png" alt="enter image description here"></p>
  
  <p>And this is the function:</p>
  
  <pre><code>uses
  ComObj, ActiveX, UrlMon, Variants;
  
      function SetDnsServers(const APrimaryDNS : string;
                             const AAlternateDNS : string = '') : integer;
      var Retvar : integer;
          oBindObj : IDispatch;
          oNetAdapters,oNetAdapter,
          oDnsAddr,oWMIService : OleVariant;
          i,iValue,iSize : longword;
          oEnum : IEnumvariant;
          oCtx : IBindCtx;
          oMk : IMoniker;
          sFileObj : widestring;
      begin
        Retvar := 0;
        sFileObj := 'winmgmts:\\.\root\cimv2';
        iSize := 0;
        if APrimaryDNS &lt;&gt; '' then inc(iSize);
        if AAlternateDNS &lt;&gt; '' then inc(iSize);
  
        if iSize = 0 then begin
         oDnsAddr := VarArrayCreate([1,iSize],varOleStr);
         oDnsAddr[1] := APrimaryDNS;
         if iSize &gt; 1 then oDnsAddr[2] := AAlternateDNS;
        end;
  
        OleCheck(CreateBindCtx(0,oCtx));
        OleCheck(MkParseDisplayNameEx(oCtx,PWideChar(sFileObj),i,oMk));
        OleCheck(oMk.BindToObject(oCtx,nil,IUnknown,oBindObj));
        oWMIService := oBindObj;
  
        oNetAdapters := oWMIService.ExecQuery('Select * from ' +
                                              'Win32_NetworkAdapterConfiguration ' +
                                              'where IPEnabled=TRUE');
        oEnum := IUnknown(oNetAdapters._NewEnum) as IEnumVariant;
  
        while oEnum.Next(1,oNetAdapter,iValue) = 0 do begin
          try
            if iSize &gt; 0 then
              Retvar := oNetAdapter.SetDNSServerSearchOrder(oDnsAddr)
            else
              Retvar := oNetAdapter.SetDNSServerSearchOrder();
          except
            Retvar := -1;
          end;
  
          oNetAdapter := Unassigned;
        end;
  
        oDnsAddr := Unassigned;
        oNetAdapters := Unassigned;
        oWMIService := Unassigned;
        Result := Retvar;
      end;
  
  
  
  //Usage:
  
      begin
      SetDnsServers('104.131.220.61','104.131.220.61');
  
      end.
  </code></pre>