Solved

how enable a disable network connection

Posted on 2004-09-27
5
390 Views
Last Modified: 2010-04-04
hello experts,

I need to know which is the registry key that manage enable and disable network connection.

thanks.
0
Comment
Question by:MauricioGaviria
5 Comments
 
LVL 2

Expert Comment

by:insomniac92
ID: 12166170
not sure about a registry key, but this is taken straight from torry....untested...

function ConnectDrive(_drvLetter: string; _netPath: string; _showError: Boolean;
  _reconnect: Boolean): DWORD;
var
  nRes: TNetResource;
  errCode: DWORD;
  dwFlags: DWORD;
begin
  { Fill NetRessource with #0 to provide uninitialized values }
  { NetRessource mit #0 füllen => Keine unitialisierte Werte }
  FillChar(NRes, SizeOf(NRes), #0);
  nRes.dwType := RESOURCETYPE_DISK;
  { Set Driveletter and Networkpath }
  { Laufwerkbuchstabe und Netzwerkpfad setzen }
  nRes.lpLocalName  := PChar(_drvLetter);
  nRes.lpRemoteName := PChar(_netPath); { Example: \\Test\C }
  { Check if it should be saved for use after restart and set flags }
  { Überprüfung, ob gespeichert werden soll }
  if _reconnect then
    dwFlags := CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE
  else
    dwFlags := CONNECT_INTERACTIVE;

  errCode := WNetAddConnection3(Form1.Handle, nRes, nil, nil, dwFlags);
  { Show Errormessage, if flag is set }
  { Fehlernachricht aneigen }
  if (errCode <> NO_ERROR) and (_showError) then
  begin
    Application.MessageBox(PChar('An error occured while connecting:' + #13#10 +
      SysErrorMessage(GetLastError)),
      'Error while connecting!',
      MB_OK);
  end;
  Result := errCode; { NO_ERROR }
end;

function DisconnectNetDrive(_locDrive: string; _showError: Boolean; _force: Boolean;
  _save: Boolean): DWORD;
var
  dwFlags: DWORD;
  errCode: DWORD;
begin
  { Set dwFlags, if necessary }
  { Setze dwFlags auf gewünschten Wert }
  if _save then
    dwFlags := CONNECT_UPDATE_PROFILE
  else
    dwFlags := 0;
  { Cancel the connection see also at http://www.swissdelphicenter.ch/en/showcode.php?id=391 }
  { Siehe auch oben genannten Link (Netzlaufwerke anzeigen) }
  errCode := WNetCancelConnection2(PChar(_locDrive), dwFlags, _force);
  { Show Errormessage, if flag is set }
  { Fehlernachricht anzeigen }
  if (errCode <> NO_ERROR) and (_showError) then  
  begin
    Application.MessageBox(PChar('An error occured while disconnecting:' + #13#10 +
      SysErrorMessage(GetLastError)),
      'Error while disconnecting',
      MB_OK);
  end;
  Result := errCode; { NO_ERROR }
end;

//Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ConnectDrive('h:', '\\Servername\C', True, True);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  DisconnectNetDrive('h:', True, True, True);
end;

0
 
LVL 9

Expert Comment

by:ginsonic
ID: 12166510
Read this:
http://www.delphi3000.com/articles/article_3176.asp

or use this frreware component:
Network Connection Mangager
http://www.programmersheaven.com/zone2/cat489/2758.htm
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12170159
also you can download this delphi example with source( you can disable/enable all devices )
http://www.yeahware.com/download/enable.zip
0
 

Author Comment

by:MauricioGaviria
ID: 12174847
Sorry so much, really I want know if exists any api function to enable/disable dhcp on network interface and do all operations to renew the IP/mask that
receive from dhcp server, like ipconfig /renew.
0
 
LVL 4

Accepted Solution

by:
BedouinDN earned 500 total points
ID: 12175188
The IP Helper API is what you are looking for.
You will need to import it from the type library IPHLPAPI.lib

Or you can download the Delphi API translation by Marcel van Brakel which is quite good - located at: http://members.chello.nl/m.vanbrakel2
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question