ExitWindowsEx()是否适用于Windows 8 [英] Does ExitWindowsEx() work for windows 8

查看:108
本文介绍了ExitWindowsEx()是否适用于Windows 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ExitWindowsEX()函数来关闭系统。它在Windows 7和XP中工作。但是,当我在windows8中运行相同的东西时,它没有关闭。我试过这样的。



 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 ]。属性= SE_PRIVILEGE_ENABLED;
if (AdjustTokenPrivileges(hToken,FALSE,& tkp, 0 ,(PTOKEN_PRIVILEGES)NULL , 0 ))
{
// SetSystemPowerState(FALSE,TRUE);
ExitWindowsEx(EWX_SHUTDOWN, 0 );
}
}



在Windows 8中怎么做?

解决方案

好,显然是行不通的。你应该检查 WINAPI 函数返回值(也可能阅读一些文档),以便发现为什么它不是工作

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.,

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 ?

解决方案

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.


这篇关于ExitWindowsEx()是否适用于Windows 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆