automatically dial/hangup the default Internet connection

 

 

uses

  WinInet;

 

// Causes the modem to automatically dial the default Internet connection.

procedure TForm1.Button1Click(Sender: TObject);

var

  dwConnectionTypes: DWORD;

begin

  dwConnectionTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN +

    INTERNET_CONNECTION_PROXY;

  if not InternetGetConnectedState(@dwConnectionTypes, 0) then

    // not connected

    if not InternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE or

      INTERNET_AUTODIAL_FORCE_UNATTENDED, 0) then

    begin

      // error

    end;

end;

 

 

// hangup the default Internet connection.

procedure TForm1.Button2Click(Sender: TObject);

var

  dwConnectionTypes: DWORD;

begin

  dwConnectionTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN +

    INTERNET_CONNECTION_PROXY;

  if InternetGetConnectedState(@dwConnectionTypes, 0) then

    // connected

    InternetAutodialHangup(0);

end;