• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Adding and removing network connections

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
Prototype_T-104
Asked:
Prototype_T-104
  • 2
  • 2
1 Solution
 
BdLmCommented:
procedure TForm1.ConnectDrive1Click(Sender: TObject);
begin
    WNetConnectionDialog(handle,RESOURCETYPE_DISK);
end;

eg. to connect to e network drive
0
 
BdLmCommented:
remark:

RESOURCETYPE_PRINTER also available, for Disconnect call WNETDisconnectDialog
 
0
 
TheRealLokiSenior DeveloperCommented:
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
 
Prototype_T-104Author Commented:
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
 
TheRealLokiSenior DeveloperCommented:
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

Independent Software Vendors: 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!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now