Changeset View
Changeset View
Standalone View
Standalone View
source/lib/sysdep/os/win/wutil.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 454 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
WinScopedPreserveLastError s; | WinScopedPreserveLastError s; | ||||
HANDLE hToken; | HANDLE hToken; | ||||
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken)) | if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken)) | ||||
return ERR::_1; | return ERR::_1; | ||||
TOKEN_PRIVILEGES tp; | TOKEN_PRIVILEGES tp; | ||||
if (!LookupPrivilegeValueW(NULL, privilege, &tp.Privileges[0].Luid)) | if (!LookupPrivilegeValueW(nullptr, privilege, &tp.Privileges[0].Luid)) | ||||
return ERR::_2; | return ERR::_2; | ||||
tp.PrivilegeCount = 1; | tp.PrivilegeCount = 1; | ||||
tp.Privileges[0].Attributes = enable? SE_PRIVILEGE_ENABLED : 0; | tp.Privileges[0].Attributes = enable? SE_PRIVILEGE_ENABLED : 0; | ||||
SetLastError(0); | SetLastError(0); | ||||
const BOOL ok = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, 0, 0); | const BOOL ok = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, 0, 0); | ||||
if(!ok || GetLastError() != 0) | if(!ok || GetLastError() != 0) | ||||
return ERR::_3; | return ERR::_3; | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator