Solved

Adding and removing network connections

Posted on 2004-08-05
8
151 Views
Last Modified: 2010-04-05
Hey everyone,

I asked this question in a previous thread, but I was told I must ask one question at a time so here it goes: How to open the "New Connection Wizard" and how to remove already existing connections within Delphi code? I hope this can be classified as one question... :)

Thanks allot for your time!
0
Comment
Question by:Prototype_T-104
  • 2
  • 2
8 Comments
 
LVL 8

Expert Comment

by:BdLm
ID: 11725446
procedure TForm1.ConnectDrive1Click(Sender: TObject);
begin
    WNetConnectionDialog(handle,RESOURCETYPE_DISK);
end;

eg. to connect to e network drive
0
 
LVL 8

Expert Comment

by:BdLm
ID: 11725469
remark:

RESOURCETYPE_PRINTER also available, for Disconnect call WNETDisconnectDialog
 
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 145 total points
ID: 11729929
The following is how to make a connection without the dialog

function Tf.Connect( RemoteName, ShareName, UserName, Password: string): boolean;
    var
        NetError: DWORD;
        NetResource: TNetResource;
    begin
        fillChar( NetResource, sizeof( NetResource ), 0 );
        NetResource.dwType := RESOURCETYPE_DISK;
        NetResource.lpLocalName := nil;
        NetResource.lpRemoteName := PChar( RemoteName + ShareName );
        NetResource.lpProvider := nil;
        NetError := WNetAddConnection2( NetResource,
        PChar( Password ), PChar( UserName ), 0 );
        result := NetError = 0;
    end;

        WNetCancelConnection2( PChar( Machine_ + Share_), 0, true );
0
 

Author Comment

by:Prototype_T-104
ID: 11733574
Thanks I will try to implement that,

@BdLm
I want to call the dialog that creates a new connection to the internet. This dialog is also available from the Network Connections folder.
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 13341645
I answered the 2nd part of his question correctly, however the first part was only half correct.
I probably should have checked back and followed up on his question but I forgot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 108
Error E2158 compiling with Delphi XE10 Seattle 2 86
Performance of SQL statement 37 97
tvirtualstringtree freeze when load too manny images 10 52
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now