Cry about...
Delphi Programming with WinInet


How to switch the WinInet system on or off-line


The following procedure will switch the WinInet system on-line or off-line according to the value of the flag it is called with.

/////////////////////////////////////////////////////////////////////////
// This procedure sets the WinInet API offline, or online.
/////////////////////////////////////////////////////////////////////////
procedure SetGlobalOffline(goOffline: boolean);
var
  connect_info: TInternetConnectedInfo;
begin
  if goOffline then
  begin
    connect_info.dwConnectedState := INTERNET_STATE_DISCONNECTED_BY_USER;
    connect_info.dwFlags := ISO_FORCE_DISCONNECTED;
  end
  else
  begin
    connect_info.dwConnectedState := INTERNET_STATE_CONNECTED;
    connect_info.dwFlags := 0;
  end;
  InternetSetOption(nil,INTERNET_OPTION_CONNECTED_STATE,
    @connect_info,sizeof(connect_info));
end;

Be aware that changing the state on-line or off-line will affect all other programs that use the WinInet system. This will include Internet Explorer, Outlook Express and others.


These notes are believed to be correct for Delphi 6, but may apply to other versions as well.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.