this is probably going to be a easy one for u all but i dont get it..
why wont this code compile ?? do i need to include a .lib ?
#include <windows.h>
Code:
BOOL fResult;
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
MessageBox(NULL,NULL,"OpenProcessToken failed.", MB_OK | MB_ICONINFORMATION);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
MessageBox(NULL,NULL,"AdjustTokenPrivileges enable failed.",MB_OK | MB_ICONINFORMATION);
fResult = InitiateSystemShutdown(
NULL,
"Click on the main window and press the Escape key to cancel shutdown.",
3,
TRUE,
TRUE);
if (!fResult)
{
MessageBox(NULL,NULL,"InitiateSystemShutdown failed.",MB_OK | MB_ICONINFORMATION);
}
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
{
MessageBox(NULL,NULL,"AdjustTokenPrivileges disable failed.",MB_OK | MB_ICONINFORMATION);
}
return 0;
}