setting UAC settings of a file in C#

前端 未结 3 956
谎友^
谎友^ 2020-12-12 05:00

i want to give a file(already present on the client computer .exe) permissions to always execute with administrative permissions.

please note that the file i wants

3条回答
  •  臣服心动
    2020-12-12 05:12

    Using a manifest file is the best approach, but an alternative one would be to programmatically set the "Run this program as an administrator" flag (the option you find in the Compatibility tab of an EXE's properties), by setting a simple registry key. You need to create a string value (REG_SZ) under the one of these keys (if you want the setting to be per user or per machine, respectively):

    HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

    or

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

    The name of the value needs to be the full path to your executable (if the path contains spaces, do not surround the path with quotes), and the data of the value must contain the string RUNASADMIN.

提交回复
热议问题