title: How to Detect LAN or Adapter that is installed by openVPN?
body: <p>I am using Visual Basic 2010. I've installed openVPN and its Adapter. I want to make application that will use the Adapter from openVPN. How can I detect it?</p>
  
  <p>I have the code for Delphi. But I don't understand it at all. Its something like this:</p>
  
  <pre><code>// INI ADALAH BAGIAN UNTUK MENDAPATKAN NAMA INTERFACE NETWORK
  
  uses WbemScripting_TLB, activex;
  
  type TIWrapper=class
   public
     prop:ISWbemProperty;
     constructor Create(p:ISWbemProperty);
   end;
  
  constructor TIWrapper.Create(p: ISWbemProperty);
  begin
    prop:=p;
  end;
  
  procedure clear(Adapters:TStrings);
  var i:integer;
  begin
    for i:=1 to Adapters.Count do
    begin
      Adapters.Objects[i-1].Free;
      Adapters.Objects[i-1]:=nil;
    end;
    Adapters.Clear;
  end;
  
  function getPropValue(sprop:ISWbemProperty):string;
  var sValue:string;
      count:integer;
  begin
    sValue := '';
    if VarIsNull(SProp.Get_Value) then
      sValue := '&lt;empty&gt;'
    else
    case SProp.CIMType of
      wbemCimtypeSint8, wbemCimtypeUint8, wbemCimtypeSint16, wbemCimtypeUint16,
      wbemCimtypeSint32, wbemCimtypeUint32, wbemCimtypeSint64:
        sValue := IntToStr(SProp.Get_Value);
      wbemCimtypeString, wbemCimtypeUint64:
        if VarIsArray(SProp.Get_Value) then
        begin
          if VarArrayHighBound(SProp.Get_Value, 1) &gt; 0 then
            for Count := 1 to VarArrayHighBound(SProp.Get_Value, 1) do
          sValue := sValue + ' ' + SProp.Get_Value[Count];
    end
  else
    sValue :=  SProp.Get_Value;
  wbemCimtypeDatetime:sValue:=SProp.Get_Value//DateTimeToStr(SProp.Get_Value)
   else
    Exception.Create('Unknown type');
    end; {case}
    result:=sValue;
  end;
  
  procedure getAdapters(owner:TComponent; RemoteMachine,RemoteUser,RemotePassword:string; Adapters:TStrings);
  var
    Locator: TSWbemLocator;
    SinkClasses: TSWbemSink;
  
    Services:   ISWbemServices;
    ObjectSet:  ISWbemObjectSet;
    SObject:    ISWbemObject;
    propSet :   ISWbemPropertySet;
    SProp:      ISWbemProperty;
    Enum:       IEnumVariant;
    tempObj:    OleVariant;
   Value:      Cardinal;
  
   sValue,
   className:     String;
   strQuery:   WideString;
   begin
   className:='WIN32_NetworkAdapter';
   clear(adapters);
  
   Locator:=TSWbemLocator.Create(owner);
   SinkClasses:=TSWbemSink.Create(owner);
   try
     SinkClasses.Cancel;
  
  if RemoteMachine='' then
    RemoteMachine:='.';// local machine
  Services := Locator.ConnectServer(RemoteMachine, 'root\CIMV2', RemoteUser, RemotePassword, '',
    '', 0, nil);
  try
    ObjectSet := Services.InstancesOf(className, wbemFlagReturnImmediately or wbemQueryFlagShallow, nil);
    Enum :=  (ObjectSet._NewEnum) as IEnumVariant;
    try
      while (Enum.Next(1, tempObj, Value) = S_OK) do
      begin
        SObject := IUnknown(tempObj) as SWBemObject;
        propSet := SObject.Properties_;
        SProp:=propSet.Item('NetConnectionID',0);// caption or systemname
        // now get the value of the property
        sValue:=getPropValue(SProp);
        try
          if sValue&lt;&gt;'&lt;empty&gt;' then
          begin
            sProp:=propSet.Item('NetConnectionStatus',0);
            Adapters.AddObject(sValue,TIWrapper.Create(SProp));
          end;
        finally
          SObject:=nil;
          propSet:=nil;
          SProp:=nil;
        end;
      end; {while Enum}
    finally
      ObjectSet:=nil;
      enum:=nil;
    end;
  
    strQuery := 'SELECT * FROM __InstanceCreationEvent within 5 WHERE TargetInstance' +
      ' ISA "'+className+'"';
    Services.ExecNotificationQueryAsync(SinkClasses.DefaultInterface, strQuery, 'WQL', 0, nil, nil);
      strQuery := 'SELECT * FROM __InstanceDeletionEvent within 5 WHERE TargetInstance' +
      ' ISA "'+className+'"';
    Services.ExecNotificationQueryAsync(SinkClasses.DefaultInterface, strQuery, 'WQL', 0, nil, nil);
     finally
    Services:=nil;// make sure the references are decreased
  end;
    finally
  Locator.Free;
  SinkClasses.Free;
    end; {try}
  end;
  
  // AKHIR CODE MENDAPATKAN INTERFACE NETWORK 
  </code></pre>