Create a file switching user in the same process
I have a program that needs to create a file in a directory where the user who is running the application doesn't has permission to write, but other user has. Is possible to do that?
I know that I can login a user with write privileges in that folder with LogonUserA, but then I don't know how to create a file using the returned token. Also, I know the user na开发者_如何学编程me and password of the user who can write in that directory.
I use Delphi, but the example or ideas could be in any language.
HANDLE hToken = LogonUser(...);
ImpersonateLoggedOnUser(hToken);
// do something
RevertToSelf();
CloseHandle(hToken);
精彩评论