medfall

A super great game engine
Log | Files | Refs

commit c40214cdddba6b2b34dc8b87a639d6c12007ecbc
parent 50e38a7f3d24425f97cc2af8b930f31b9af27bc3
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat, 11 Nov 2017 17:32:47 +0200

Use ShellExecute to elevate because CreateProcessA doesn't work

Diffstat:
elevate_for_update.cc | 2+-
win32_exec.h | 20++++++++++++--------
2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/elevate_for_update.cc b/elevate_for_update.cc @@ -3,6 +3,6 @@ #include "win32_exec.h" int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, char * szCmdLine, int iCmdShow ) { - exec_and_quit( NULL, "launch.exe --start-update" ); + exec_and_quit( "launch.exe", "--start-update" ); return 1; } diff --git a/win32_exec.h b/win32_exec.h @@ -1,18 +1,22 @@ #pragma once #include <windows.h> +#include <shellapi.h> #include "log.h" -void exec_and_quit( const char * path, char * command_line = NULL ) { - STARTUPINFOA startup_info = { }; - startup_info.cb = sizeof( startup_info ); - - PROCESS_INFORMATION process_info = { }; +#pragma warning( push ) +#pragma warning( disable : 4302 ) +#pragma warning( disable : 4311 ) - if( CreateProcessA( path, command_line, 0, 0, FALSE, 0, NULL, NULL, &startup_info, &process_info ) == 0 ) { - FATAL( "CreateProcess" ); - } +void exec_and_quit( const char * path, char * command_line = NULL ) { + int ok = int( ShellExecute( NULL, "runas", path, command_line, NULL, SW_SHOWDEFAULT ) ); + if( ok == SE_ERR_ACCESSDENIED ) + return; + if( ok <= 32 ) + FATAL( "ShellExecute" ); exit( 0 ); } + +#pragma warning( pop )