mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-02 06:40:42 -07:00
launcher: option to run as user without elevation (#695)
## Link to GitHub Issue or related Pull Request, if one exists #694 ## Description of change Before this change, we have it set in the executable manifest to always ask for UAC elevation. This change removes that and instead attempts to prompt for elevation when we launch, depending on the new developer option that is being added here to run as current user instead of elevating. The default behavior continues to run as admin. This is still the safest in terms of regression risk. A bit of history on this: while spicecfg never technically needed to elevate, we continue to do so to avoid difference in behavior when the game is launched. For example, if the user is using an input remapper running without elevation, it would inject input into spicecfg running as user but fail to do so if the game runs elevated. WinXP builds are unaffected (there is no UAC). Some features will straight up fail without elevation so this will remain as a debug option. To name a few (not a complete list): * reboot/shutdown of PC * running at realtime process priority * `-nvprofile` option * ... ## Testing
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <shlwapi.h>
|
||||
#include <windows.h>
|
||||
#include <cfg/configurator.h>
|
||||
|
||||
#include "api/modules/capture.h"
|
||||
@@ -301,6 +302,26 @@ int main_implementation(int argc, char *argv[]) {
|
||||
}
|
||||
auto &options = *options_ptr;
|
||||
|
||||
#if !SPICE_XP
|
||||
|
||||
{
|
||||
// skip elevation only if AutoElevate is explicitly set to "user"
|
||||
const bool skip_elevation = options[launcher::Options::AutoElevate].is_active() &&
|
||||
options[launcher::Options::AutoElevate].value_text() == "user";
|
||||
if (!skip_elevation && !sysutils::is_running_as_admin()) {
|
||||
log_info("launcher", "relaunching with administrator privileges");
|
||||
if (sysutils::relaunch_as_admin()) {
|
||||
exit(0);
|
||||
} else {
|
||||
// elevation failed or was denied by the user
|
||||
log_fatal("launcher", "failed to launch with administrator privileges");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !SPICE_XP
|
||||
|
||||
// check options
|
||||
// TODO: get rid of some booleans here and make use of the options directly
|
||||
if (options[launcher::Options::OpenConfigurator].value_bool()) {
|
||||
|
||||
Reference in New Issue
Block a user