DelphiFAQ Home Search:
General :: Programming :: Delphi :: Network
Network (local network and Internet) programming under Windows with Delphi.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Detect whether the network is installed

Question:

I need to programmatically find out if a computer has the network installed.

Answer:

You can use the Windows function GetSystemMetrics(SM_NETWORK). This will tell you if the Windows installation includes network connection(s).

Sometimes it is claimed that this function will detect whether the machine is actually attached to a network. This is not true. The function will return the same resullts if the network connection is disabled and your computer is thus offline (not part of the network).

{sc-----------------------------------------------------------------------
   Name:       TForm1.Button1Click
   Parameters:
      Sender
 -----------------------------------------------------------------------sc}
 procedure TForm1.Button1Click(Sender: TObject);
 begin { TForm1.Button1Click }
   if GetSystemMetrics(SM_NETWORK) and $01=$01 then
     ShowMessage('Computer is attached to a network!')
   else
     ShowMessage('Computer is not attached to a network!')
 end; { TForm1.Button1Click }
 

Generated 8:01:31 on Aug 25, 2019