From: Zebediah Figura zfigura@codeweavers.com
--- programs/winetest/main.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/programs/winetest/main.c b/programs/winetest/main.c index a939034e8b9..dc4fc4b3581 100644 --- a/programs/winetest/main.c +++ b/programs/winetest/main.c @@ -687,6 +687,21 @@ extract_test (struct wine_test *test, const char *dir, LPSTR res_name) CloseHandle(hfile); }
+static HANDLE get_admin_token(void) +{ + TOKEN_ELEVATION_TYPE type; + TOKEN_LINKED_TOKEN linked; + DWORD size; + + if (!GetTokenInformation(GetCurrentThreadEffectiveToken(), TokenElevationType, &type, sizeof(type), &size) + || type == TokenElevationTypeFull) + return NULL; + + if (!GetTokenInformation(GetCurrentThreadEffectiveToken(), TokenLinkedToken, &linked, sizeof(linked), &size)) + return NULL; + return linked.LinkedToken; +} + static DWORD wait_process( HANDLE process, DWORD timeout ) { DWORD wait, diff = 0, start = GetTickCount(); @@ -722,6 +737,7 @@ run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, BOOL nocritic PROCESS_INFORMATION pi; DWORD wait, status, flags; UINT old_errmode; + HANDLE token = NULL;
GetStartupInfoA (&si); si.dwFlags = STARTF_USESTDHANDLES; @@ -737,8 +753,16 @@ run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, BOOL nocritic else flags = CREATE_DEFAULT_ERROR_MODE;
- if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, flags, - NULL, tempdir, &si, &pi)) + /* Some tests cause a UAC prompt on Windows if the user is not elevated, + * so to allow them to run unattended the relevant test units need to skip + * the tests if so. + * + * However, we still want Wine to run as many tests as possible, so always + * elevate ourselves. On Wine elevation isn't interactive. */ + if (running_under_wine()) + token = get_admin_token(); + + if (!CreateProcessAsUserA(token, NULL, cmd, NULL, NULL, TRUE, flags, NULL, tempdir, &si, &pi)) { if (nocritical) SetErrorMode(old_errmode); if (pid) *pid = 0;