How to elevate Perl process using UAC

前端 未结 3 1084
野趣味
野趣味 2021-01-20 17:24

Suppose I have a script that needs to read information from places that normal user is not permitted to read (e.g. other users\' folders).

Currently all I can do is

3条回答
  •  半阙折子戏
    2021-01-20 17:56

    Tired of having no good answer to this question in my own work, I wrote Win32::RunAsAdmin. All it does is call the Windows Shell via OLE with "runas" as the verb, but it packages it conveniently so all you have to do is stick the following at the beginning of your code:

    use Win32::RunAsAdmin qw(force);
    

    During the import step, it will check for elevated privileges, and return silently if you're already running in elevated mode. Otherwise, it restarts the script in elevated mode with a UAC popup.

提交回复
热议问题