Add administrator privileges Qt program in several ways

First, the project configuration

1. mingw compiler

Adding pro project file

RC_FILE=main.rc

rc file can also add a program icon 

main.rc

IDI_ICON1 ICON DISCARDABLE "./res/logo.ico" 

1 24 uac.manifest

The first line is to add icon for the program, the second line is to increase the authority, attention is manifest.

uac.manifest document reads as follows:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?> 
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> 
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
          <security>
              <requestedPrivileges> 
                  <requestedExecutionLevel level='requireAdministrator' uiAccess='false' /> 
                </requestedPrivileges> 
            </security> 
        </trustInfo> 
</assembly>

OK, so on the line. See online some friends say this method does not work, it may be the same as it does the compiler. Such use would be an error on the VS compiler, VS compiler see the second method.

2.VS compiler 

QMAKE_LFLAGS join in the project file pro QT added configuration:

QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\"

3.CMAKE, on the back of add_executable

set_target_properties(
    ${PROJECT_NAME} PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS"
)

Second, the use administrator privileges to add gadgets

/// permission.bat

start cmd /k " mt.exe -manifest "RunningPermission" -outputresource:"iphelper.exe";#1 &&taskkill /f /t /im cmd.exe"

 Kit download link: = "review ... the urgent need to leave a message

 

 

 

Published 101 original articles · won praise 26 · views 70000 +

Guess you like

Origin blog.csdn.net/weixin_39568531/article/details/104825816
Recommended