Mercurial > trustbridge
diff cinst/windowsstore.c @ 247:4de97f74d038
Check for process elevation and write into system store accordingly
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 31 Mar 2014 08:02:46 +0000 |
parents | 53ea9b975d1c |
children | 3595ea4fd3fb |
line wrap: on
line diff
--- a/cinst/windowsstore.c Sat Mar 29 15:19:45 2014 +0100 +++ b/cinst/windowsstore.c Mon Mar 31 08:02:46 2014 +0000 @@ -185,8 +185,27 @@ return; } +static bool is_elevated() { + HANDLE hToken = NULL; + bool ret = false; + if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken)) + { + TOKEN_ELEVATION elevation; + DWORD cbSize = sizeof (TOKEN_ELEVATION); + if (GetTokenInformation (hToken, TokenElevation, &elevation, + sizeof (TokenElevation), &cbSize)) + { + ret = elevation.TokenIsElevated; + } + } + if (hToken) + CloseHandle (hToken); + + return ret; +} + int -write_stores_win (char **to_install, char **to_remove, bool user_store) +write_stores_win (char **to_install, char **to_remove) { HCERTSTORE hStore = NULL; @@ -196,7 +215,7 @@ return 0; } - if (user_store) + if (!is_elevated()) { hStore = CertOpenStore (CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root");