1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#define STRICT
#include<windows.h>
/*************************************************/
BOOL EnablePrivilege(HANDLE hToken, LPCTSTR szPrivName, BOOL fEnable) {
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
LookupPrivilegeValue(NULL, szPrivName, &tp.Privileges[0].Luid);
tp.Privileges[0].Attributes = ( fEnable ? SE_PRIVILEGE_ENABLED : 0 );
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
return ( (GetLastError() == ERROR_SUCCESS) );
}
int main(int argc, _TCHAR* argv[])
{
HANDLE hToken;
MessageBox(NULL, argv[1], __TEXT("EnableDebugPrivAndRun: ok"), MB_OK | MB_ICONINFORMATION);
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES,&hToken))
{
if (EnablePrivilege(hToken, SE_DEBUG_NAME, TRUE)) {
if (ShellExecute(NULL, NULL, argv[1], NULL, NULL, SW_SHOWNORMAL) < (HINSTANCE)32) {
MessageBox(NULL, argv[1], __TEXT("EnableDebugPrivAndRun:Couldn't run"), MB_OK | MB_ICONINFORMATION);
}
}
CloseHandle(hToken);
}
return(0);
}
|