Re: CopyFile across network / logon
From: Chris P. [MVP] (msdn_at_chrisnet.net)
Date: 08/19/04
- Next message: Jaffa: "In LSP forward (reconnect socket) packet to listening server"
- Previous message: Chris P. [MVP]: "Re: CopyFile across network / logon"
- In reply to: Chris P. [MVP]: "Re: CopyFile across network / logon"
- Next in thread: flox: "Re: CopyFile across network / logon"
- Reply: flox: "Re: CopyFile across network / logon"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 19 Aug 2004 12:37:15 -0400
Chris P. [MVP] wrote:
> flox wrote:
>> Hi!
>>
>> I have a problem using CopyFile from one PC to another:
>>
>> I get a "unknown user..." error. Only after accessing the destination
>> PC using Explorer and entering user/password I can call CopyFile
>> without error. I am accessing W2K and NT workstations from a XP or
>> W2KTS system, there is NO logon box when my program calls CopyFile...
>>
>> This is ok as only authenticated users should be able to copy files
>> but using Explorer to enter user/password definitely is not a very
>> good solution...
>>
>> Unfortunately I CANNOT create the same users on both systems due to
>> security restrictions, but I have the user/password for the low
>> security systems I want to copy files to. The problem is that there
>> is no version of CopyFile taking user/password (of the remote machine
>> I want to copy to) what can I do?
>
> The thread that is going to do the copy can authenticate itself with
> the destination (server) using WNetAddConnection2() or equivilant.
> You can do it completely hidden from the user if you know the
> username and password at run time or you can prompt the user if
> necessary by using the CONNECT_INTERACTIVE flag. You don't need to
> map a local drive, set that field to NULL.
>
> Here's an example.
Sorry, hit the wrong key. Here's an example that assumes you know the
username and password:
char path[80];
UINT error=0;
NETRESOURCE nr;
CString Password = password;
memset(&nr, 0, sizeof(NETRESOURCE));
if (*server_path)
sprintf(path, "\\\\%s\\%s",server_name, server_path);
else
sprintf(path, "\\\\%s",server_name);
nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = NULL;
nr.lpRemoteName = path;
nr.lpProvider = NULL;
//retryconnect:
if (*username == 0)
{
if (*password == 0)
error = WNetAddConnection2(&nr, NULL, NULL, 0);
else
error = WNetAddConnection2(&nr, Password, NULL, 0);
}
else
error = WNetAddConnection2(&nr, Password, username, 0);
- Next message: Jaffa: "In LSP forward (reconnect socket) packet to listening server"
- Previous message: Chris P. [MVP]: "Re: CopyFile across network / logon"
- In reply to: Chris P. [MVP]: "Re: CopyFile across network / logon"
- Next in thread: flox: "Re: CopyFile across network / logon"
- Reply: flox: "Re: CopyFile across network / logon"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|