Skip to content

Commit

Permalink
chore: specify UAC level to requireAdministrator in the manifest fo…
Browse files Browse the repository at this point in the history
…r Windows (#700)

* helper: specify UAC level to requireAdministrator for Windows

So that the helper can trigger a UAC prompt upon launch, and the launch
attempt will fail if CreateProcess is used without admin privilege.

* src/app: specify UAC level to requireAdministrator for Windows

QProcess::start() can not start a new process with UAC level
requireAdministrator, since it is using CreateProcess. There is one API
that can trigger the UAC prompt, ShellExecute or ShellExecuteEx,
however, processes started by them can not be managed by QProcess.
There are some workarounds but since the QProcess instance is connected
to various slots, it would require a rewrite to apply the workarounds.
We simply specify the main app to require administrator privilege in
the manifest.
  • Loading branch information
Cyanoxygen authored and grulja committed Mar 27, 2024
1 parent aa049a2 commit 4efb8ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ if (NOT APPLE)
endif()

if (WIN32)
set_target_properties(mediawriter PROPERTIES WIN32_EXECUTABLE TRUE)
# NOTE: QProcess::start() can not start a new process with UAC level
# requireAdministrator, since it is using CreateProcess. There is one
# API that can trigger the UAC prompt, ShellExecute or ShellExecuteEx,
# but process started by them can not be managed by QProcess.
# There are some workarounds but since the QProcess instance is connected
# to various slots, it would require a rewrite to apply the workarounds.
# We simply specify the main app to require administrator privilege in
# the manifest.
set_target_properties(mediawriter PROPERTIES WIN32_EXECUTABLE TRUE
LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"")
endif()

if (WIN32)
Expand Down
6 changes: 5 additions & 1 deletion src/helper/win/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ target_link_libraries(helper
${LIBLZMA_LIBRARIES}
)

set_target_properties(helper PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src/app)
# Specify the UAC level to requireAdministrator in the manifest, in order
# to trigger a UAC prompt upon launch.
set_target_properties(helper PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src/app
LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"")

install(TARGETS helper DESTINATION ${CMAKE_INSTALL_FULL_LIBEXECDIR}/mediawriter)

0 comments on commit 4efb8ff

Please sign in to comment.