Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using ExitWindowsEX() function to shutdown system. Its working in windows 7 and XP. But when i am running in the same thing in windows8 its not shutting down. I tried like this.,

C++
HANDLE hToken; 
		TOKEN_PRIVILEGES tkp; 

		if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
		{
			LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); 
			tkp.PrivilegeCount = 1; 
			tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
			if (AdjustTokenPrivileges (hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
			   {
				//SetSystemPowerState(FALSE, TRUE);
				ExitWindowsEx(EWX_SHUTDOWN, 0);
			}
		}

How to do in windows 8 ?
Posted
Updated 21-Oct-13 23:41pm
v2

1 solution

Well, apparently is not working. You should properly check WINAPI function return values (possibly reading some documentation too) in order to discover why it is not working.
 
Share this answer
 
Comments
Richard MacCutchan 22-Oct-13 5:59am    
Hmm, why didn't I think of that?
CPallini 22-Oct-13 6:16am    
Because you were focused on quantum gravity.
By the way, thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900