Open protected folder witch password

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:

 Comp1:
 NAME:  DesktopComputer1  (My program run here)
 
 Comp2:
 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)
pwnetAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
BlackTigerXConnect With a Mentor Commented:
to connect:

procedure TForm1.Button2Click(Sender: TObject);
var
NetResource: TNetResource;
begin
  { 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
  //ERROR_ACCESS_DENIED, ERROR_ALREADY_ASSIGNED, etc
end;
0
 
BlackTigerXCommented:
to disconnect:

procedure TForm1.Button1Click(Sender: TObject);
begin
  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
  //occurred: ERROR_DEVICE_IN_USE, ERROR_NOT_CONNECTED, etc
end;
0
 
pwnetAuthor Commented:
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?

 Thanks
0
 
pwnetAuthor Commented:
Hello,

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.
0
All Courses

From novice to tech pro — start learning today.