开发者

Copy file with elevated privileges

开发者 https://www.devze.com 2022-12-18 07:22 出处:网络
Is there a way to elevate privileges to the level required to write files to a network folder with our Delphi 2006 (Win32) application?

Is there a way to elevate privileges to the level required to write files to a network folder with our Delphi 2006 (Win32) application?

The us开发者_开发技巧er running the application does not have permission to write (or view) files in the network folder in question.

Any recommended techniques or alternative suggestions?


You could prompt the user to enter credentials for a user with elevated permissions and then temporarily operate under that other user's login while writing to the network share. To do this, you are looking for the LogonUser and ImpersonateLoggedOnUser functions. Please see this answer.


Use WNetAddConnection2 to connect to the UNC path, you will need to use the lpUsername and lpPassword parameters (either ask the user for them or hide them somewhere in your app).

You can choose if you want to map a local driver letter to the UNC path or not (in that case use nil for the lpLocalname parameter). After you've done that you can access the UNC path without specifying credentials.

0

精彩评论

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