Open protected folder witch password

Posted on 2005-04-20
Last Modified: 2010-04-05
Hello experts,

I have 2 computers connected on a private network, and my program need access files on other computer protected by password, e.q:

 NAME:  DesktopComputer1  (My program run here)
 NAME:  MainServer
 UserLogin:  MyProgramAccount   (Only my program know this)
 Password:  123456

My Delphi program need connect on a Share folder on MainServer, e.q: (\\MainServer\share1\files\), but, to obtain this, it must place an UserLogin and Password. (It cannot create a network drive, because the user cannot see these files)

Okay. How to connect on a remote computer witch Username and Password, [make my activities], and close connection? (Any run on Windows 2000, or Windows 2000 Server, the login and password is Windows Account)

My Delphi Version: 6 (Personal)

Thanks for all !!

(Any question more, put here, thanks)
Question by:pwnet
    LVL 13

    Accepted Solution

    to connect:

    procedure TForm1.Button2Click(Sender: TObject);
    NetResource: TNetResource;
      { fill out TNetResource record structure }
      NetResource.dwType       := RESOURCETYPE_DISK;
      NetResource.lpLocalName  := '';
      NetResource.lpRemoteName := '\\MainServer\share1\files';
      NetResource.lpProvider   := '';

      { map our network drive using our TNetResource record structure }
      If ( WNetAddConnection2(NetResource,
                             'somepassword', {Password (if needed) or empty}
                             'somedomain\someuser', {User name (if needed) or empty}
                             CONNECT_UPDATE_PROFILE)<>NO_ERROR) Then
         Raise Exception.Create('unable to map drive')
      //there are other constants to check the error
    LVL 13

    Expert Comment

    to disconnect:

    procedure TForm1.Button1Click(Sender: TObject);
      if WNetCancelConnection2( '\\MainServer\share1\files',0,TRUE) <> NO_ERROR then
        Raise Exception.create('Error disconnecting resource');
      //of course there are also some other constants to check why the error

    Author Comment

    Hello, BlackTigerX

     I try this code in this scenary:

     My station logged on windows 2000 with user "domain\user1", and trying connect to share using "domain\user2" (user2 its only user to access then). But I get raise. The domain exists. And password is correct.

     The program is a "another login screen" for example.

     The code is not wrong, but need addictions, or no?


    Author Comment


    I'm study the problem and I give this result: "ERROR_SESSION_CREDENTIAL_CONFLICT" - 1219

    "Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again."

    How to make most connections? Why Cardinal I use to make simultaneos connections?

    This anwser close this topic, and transfer the points to you.

    Thanks for All.

    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

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    755 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

    23 Experts available now in Live!

    Get 1:1 Help Now