开发者

Create a file switching user in the same process

开发者 https://www.devze.com 2023-02-26 02:05 出处:网络
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 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消