-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[GH-9] Warning message when running Hotkey Detective as a non-admin
- Loading branch information
Showing
9 changed files
with
104 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef HOTKEY_DETECTIVE_INCLUDE_WINDOWSUTILS_H_ | ||
#define HOTKEY_DETECTIVE_INCLUDE_WINDOWSUTILS_H_ | ||
|
||
#include <windows.h> | ||
|
||
namespace WindowsUtils { | ||
/*! | ||
* \brief Check if the running user has administrator privileges. | ||
* | ||
* @return If the running user has administrator privileges, the function | ||
* returns true. Otherwise, when the user doesn't belong to the "Administrators" | ||
* group, or there are errors while checking the affiliation, the result is | ||
* false. | ||
*/ | ||
BOOL isUserAdmin(); | ||
|
||
/*! | ||
* \brief Return a read-only pointer to a string resource. | ||
* | ||
* This function can be used to retrieve a read-only pointer to any string | ||
* resource defined in this application. | ||
* | ||
* @param[in] strResource an ID of the string resource | ||
* @return If the function succeeds, the return value is a read-only pointer to | ||
* the desired string resource. Otherwise, the return value is a nullptr. | ||
*/ | ||
const wchar_t *resStr(int strResource); | ||
} | ||
|
||
#endif //HOTKEY_DETECTIVE_INCLUDE_WINDOWSUTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#include "resource.h" | ||
|
||
IDI_MAIN_ICON ICON "main.ico" | ||
ID_ICON_MAIN ICON "main.ico" | ||
|
||
STRINGTABLE | ||
BEGIN | ||
ID_STRING_APP_NAME "Hotkey Detective" | ||
ID_STRING_ADMIN_WARNING "You are trying to run Hotkey Detective without administrator privileges. If you proceed, Hotkey Detective won't be able to detect all hotkeys. Are you sure you want to continue?" | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "WindowsUtils.h" | ||
|
||
#include <securitybaseapi.h> | ||
|
||
BOOL WindowsUtils::isUserAdmin() { | ||
SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY; | ||
PSID administratorsGroup; | ||
|
||
BOOL result = AllocateAndInitializeSid(&authority, 2, | ||
SECURITY_BUILTIN_DOMAIN_RID, | ||
DOMAIN_ALIAS_RID_ADMINS, | ||
0, 0, 0, 0, 0, 0, | ||
&administratorsGroup); | ||
|
||
if (result) { | ||
// If this call fails, that means an error, so we can as well assume | ||
// the user has no admin rights. | ||
if (!CheckTokenMembership(nullptr, administratorsGroup, &result)) { | ||
result = FALSE; | ||
} | ||
|
||
FreeSid(administratorsGroup); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
const wchar_t *WindowsUtils::resStr(int strResource) { | ||
HINSTANCE hInstance = GetModuleHandleW(nullptr); | ||
|
||
const wchar_t* strPtr = nullptr; | ||
LoadStringW(hInstance, strResource, (LPWSTR) &strPtr, 0); | ||
|
||
return strPtr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters