Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how enable a disable network connection

Posted on 2004-09-27
5
Medium Priority
?
423 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 1500 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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