Solved

how enable a disable network connection

Posted on 2004-09-27
5
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2 77
SUM 2 INTEGER ARRAYS INTO 1 10 111
Tvertscrollbox like a whatsapp layout delete messages 1 39
Add New Database Table in database file using delphi 3 32
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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