QtAutoUpdater  3.0.0
A Qt library to automatically check for updates and install them
Functions
QtAutoUpdater::AdminAuthoriser Namespace Reference

Methods to run applications as authorized user (admin/root) More...

Functions

Q_AUTOUPDATERCORE_EXPORT bool needsAdminPermission (const QString &program)
 Tries to find out if the given executable needs to be run as priviledged user. More...
 
Q_AUTOUPDATERCORE_EXPORT bool executeAsAdmin (const QString &program, const QStringList &arguments, const QString &workingDir)
 Prompts the user to execute the given executable as priviledged user. More...
 

Detailed Description

Methods to run applications as authorized user (admin/root)

The AdminAuthoriser's task is to run a program with elevated rigths. Since the way to archive this is different on every platform, it will behave differently on different systems. Generelly it will prompt the user for admin credentials using the system API and then execute the program on success. This may not work on any platform.

This namespace can be used when implementing custom plugins to run elevated tasks

Function Documentation

◆ executeAsAdmin()

QtAutoUpdater::AdminAuthoriser::executeAsAdmin ( const QString program,
const QStringList arguments,
const QString workingDir 
)

Prompts the user to execute the given executable as priviledged user.

Parameters
programThe path to the executable. This will be an absolute path
argumentsA list of arguments to be passed to the executable
workingDirThe working directory to execute the program in. Should always be a valid path
Returns
true, if the program could be started with elevated rights, false if not

This function will try to prompt the user for elevation and the execute the given program with elevation. Please note that workingDir may be ignored on some platforms. You should not rely on it beeing set correctly. Also, it may return true, even if the user rejected priviledged execution.

This function can return false if:

  1. The user rejected the priviledged execution (but this may result in a successful return as well)
  2. The user accepted, but the operating system was not able to start the process
  3. The execution is not supported on the current platform
See also
AdminAuthoriser::needsAdminPermission

◆ needsAdminPermission()

QtAutoUpdater::AdminAuthoriser::needsAdminPermission ( const QString program)

Tries to find out if the given executable needs to be run as priviledged user.

Returns
true, if this program needs to be run as priviledged user, false if not or unable to determine

This might return false even if a application needs such permissions in three cases:

  1. The system is unable to figure out, whether the program needs that permission
  2. The current application is already running with elevated rights
  3. The check is not supported on the current platform
See also
AdminAuthoriser::executeAsAdmin