| 173 | |
| 174 | |
| 175 | bool SetPrivilege( HANDLE hToken, LPCTSTR lpPrivilege, bool bEnablePrivilege ) |
| 176 | { |
| 177 | NTSTATUS Status; |
| 178 | LUID privLuid; |
| 179 | TOKEN_PRIVILEGES tokenPriv; |
| 180 | TOKEN_PRIVILEGES tokenPrivPrevious; |
| 181 | DWORD cbPrevious; |
| 182 | |
| 183 | if (!LookupPrivilegeValue( NULL, lpPrivilege, &privLuid )) |
| 184 | return false; |
| 185 | |
| 186 | ZeroMemory( &tokenPriv, sizeof( tokenPriv ) ); |
| 187 | tokenPriv.PrivilegeCount = 1; |
| 188 | tokenPriv.Privileges[0].Luid = privLuid; |
| 189 | tokenPriv.Privileges[0].Attributes = 0; |
| 190 | |
| 191 | cbPrevious = sizeof( TOKEN_PRIVILEGES ); |
| 192 | Status = ntdll::NtAdjustPrivilegesToken( hToken, FALSE, &tokenPriv, sizeof( TOKEN_PRIVILEGES ), &tokenPrivPrevious, &cbPrevious ); |
| 193 | if (!NT_SUCCESS( Status )) |
| 194 | return false; |
| 195 | |
| 196 | tokenPrivPrevious.PrivilegeCount = 1; |
| 197 | tokenPrivPrevious.Privileges[0].Luid = privLuid; |
| 198 | if (bEnablePrivilege) |
| 199 | tokenPrivPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED); |
| 200 | else |
| 201 | tokenPrivPrevious.Privileges[0].Attributes ^= (SE_PRIVILEGE_ENABLED & tokenPrivPrevious.Privileges[0].Attributes); |
| 202 | |
| 203 | Status = ntdll::NtAdjustPrivilegesToken( hToken, FALSE, &tokenPrivPrevious, cbPrevious, NULL, NULL ); |
| 204 | if (!NT_SUCCESS( Status )) |
| 205 | return false; |
| 206 | |
| 207 | return true; |
| 208 | } |
| 209 | |
| 210 | bool SetDebugPrivilege( bool bEnable ) |
| 211 | { |