开发者

How to launch an application with admin rights

开发者 https://www.devze.com 2022-12-17 08:26 出处:网络
I want to launch an application with admin rights. If it runs with limited user, a popup will appear (same as \"Run as\" context menu) so that user will input an Administrator account (user & pass

I want to launch an application with admin rights. If it runs with limited user, a popup will appear (same as "Run as" context menu) so that user will input an Administrator account (user & pass), & switch my application rights to this user. Becau开发者_Go百科se my application will need permissions to operate.

I want to implement this feature in XP, & Vista.

Thanks.


this can be solved with the Impersonator class:

http://www.codeproject.com/KB/cs/zetaimpersonator.aspx

or this ImpersonateUser function:

http://www.codeproject.com/KB/cs/cpimpersonation1.aspx

some other options are to execute RunAs /user:administrator "program"

or add this to your original app's .manifest file (so privs are requested once at the start)

<requestedPrivileges>
  <requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
0

精彩评论

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