home *** CD-ROM | disk | FTP | other *** search
- /* This routine manipulates process privileges. The "fEnable" flag determines
- whether to turn on the specified privilege or turn off all privileges. The
- "PrivString" parameter specifies which privilege to enable.
- */
-
- #include "apierr.h"
-
- BOOL AdjustProcessPrivs (LPTSTR PrivString, BOOL fEnable)
- {
-
- HANDLE hToken;
- LUID TakeOwnershipValue;
- TOKEN_PRIVILEGES tkp;
-
- /* Get the handle of the access token */
-
- if (!OpenProcessToken (
- GetCurrentProcess (),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
- &hToken))
-
- {
- PERR ("OpenProcessToken");
- return FALSE;
- }
-
- /* Enable or disable the privilege, depending on the fEnable flag */
-
- if (fEnable)
- {
- if (!LookupPrivilegeValue (
- (LPSTR) NULL,
- PrivString,
- &TakeOwnershipValue))
-
- {
- PERR ("LookupPrivilegeValue");
- return FALSE;
- }
-
- tkp.PrivilegeCount = 1;
- tkp.Privileges[0].Luid = TakeOwnershipValue;
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
-
- AdjustTokenPrivileges (
- hToken,
- FALSE,
- &tkp,
- sizeof (TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES) NULL,
- (PDWORD) NULL);
-
- if (GetLastError () != ERROR_SUCCESS)
- {
- PERR ("AdjustTokenPrivileges");
- return FALSE;
- }
- }
- else
- {
- AdjustTokenPrivileges (
- hToken,
- TRUE,
- (PTOKEN_PRIVILEGES) NULL,
- (DWORD) 0,
- (PTOKEN_PRIVILEGES) NULL,
- (PDWORD) NULL);
-
- if (GetLastError () != ERROR_SUCCESS)
- {
- PERR ("AdjustTokenPrivileges");
- return FALSE;
- }
- }
-
- return TRUE;
- }
-