Solved

Adding and removing network connections

Posted on 2004-08-05
8
150 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

16 Experts available now in Live!

Get 1:1 Help Now