Solved

Adding and removing network connections

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

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 57
Working with hours 3 64
Convert a string into a TDateTime 5 63
Dev express lookupcombo 3 34
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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