Win C#: Run app as administrator without UAC prompt

前端 未结 2 1286
野趣味
野趣味 2020-12-28 18:25

I need one of my .exe to always run as administrator without UAC prompt. My program will be installed with setup, which will have for one time admin rights, and I need to pe

相关标签:
2条回答
  • 2020-12-28 18:48

    If it were possible to do this, then UAC would be completely ineffective. The inability of applications to elevate themselves without user consent is the fundamental principle behind UAC.

    Aside from already having an elevated process that launches it (i.e. service or task scheduler), the answer is no, it can't be done.

    0 讨论(0)
  • 2020-12-28 18:56

    Of course what you are supposed to do if you want to just drive UI is to use the UI access flag in your manifest (see http://msdn.microsoft.com/en-us/library/ms742884.aspx). If you install your application in a trusted location (e.g. system32) and it is signed (bleh!) then when you run your application it will be elevated to high (for an admin account).

    The signing requirement makes it slightly annoying but at least it reduces slightly the attack surface as your code gets run with high integrity but not with an administrator token.

    0 讨论(0)
提交回复
热议问题