Hi,
I'm using pure win32 (no atl or mfc) to copy files from my pc to other pc.
Currently I'm administrator of the other person's pc so my copy of file is
successful without a problem by using following code:
BOOL ret =CopyFile(existingfilename,TEXT("\\\\pc5\\c$\\sample2.txt"),
FALSE );
This works fine. Now my concern is that if I'm not an admin of the other
guy's pc, it'll require username and password for my code to copying file.
In that case how will I specify the username and password? What apis are
used for that?
many thanks,
Ab.
William DePalo [MVP VC++] - 24 Oct 2005 15:27 GMT
> BOOL ret =CopyFile(existingfilename,TEXT("\\\\pc5\\c$\\sample2.txt"),
> FALSE );
[quoted text clipped - 3 lines]
> In that case how will I specify the username and password? What apis are
> used for that?
LogonUser(); // gets you a handle to a token
ImpersonateLoggedOnUser(); // "changes" security context
CopyFile(); // copies file under changed context
RevertToSelf(); // switches back to normal
Prior to XP you will need the SE_TCB_NAME ("act as part of the operating
system") privilege.
Regards,
Will
Abubakar - 25 Oct 2005 09:28 GMT
Thanks for reply. Its very helpful.
-Ab.
> > BOOL ret =CopyFile(existingfilename,TEXT("\\\\pc5\\c$\\sample2.txt"),
> > FALSE );
[quoted text clipped - 17 lines]
> Regards,
> Will