Hi I've been learning more and more on C/C++ as time goes on. Today I wanted to play around by creating a class that makes it easier to use Windows Tokens. I get stumped though when trying to pass a HANDLE variable by reference to a Win32 Function. It's suppose to set the HANDLE variable to a pointer but it just stays the same as I walk through the code.
This is my code:
hToken is my HANDLE variable privately declared in my AccessToken class.
Please correct my terminology if I misused and if there is a better way to do this I would really appreciate being told =D. Would really help me understand and get better at programming.
Thanks!
-Mack
This is my code:
Code:
//Security.h
#include <windows.h>
class AccessToken
{
public:
void SetPrivilege(char* lpszPrivilege);
char* GetPrivilege();
bool IsPrivilegeEnabled();
void EnablePrivilege();
void SetToken();
private:
TOKEN_PRIVILEGES tp;
LUID luid;
char* szPrivilege;
HANDLE hToken;
};
Code:
//Method taken from Security.cpp
void AccessToken::SetToken()
{
OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, FALSE, &hToken);
}
Code:
//Main.cpp
#include <cstdio>
#include <windows.h>
#include <tchar.h>
#include "Security.h"
int main()
{
AccessToken at;
at.SetPrivilege("SeDebugPrivilege");
at.SetToken();
at.EnablePrivilege();
DWORD pid = 0;
HWND wnd_wmp = FindWindowW(NULL, _T("Windows Media Player"));
GetWindowThreadProcessId(wnd_wmp, &pid);
HANDLE h_wmp = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
printf("Error: %d\n", GetLastError());
system("PAUSE");
return 0;
}
Please correct my terminology if I misused and if there is a better way to do this I would really appreciate being told =D. Would really help me understand and get better at programming.
Thanks!
-Mack
Comment