C++操作WIndow平台关机,重启,注销,可以通过JNI使用JAVA调用
void powerControl(){
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
LPTSTR szReturn = NULL ;
if (OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &luid ) ;
tp.PrivilegeCount = 1 ;
tp.Privileges[0].Luid = luid ;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ;
AdjustTokenPrivileges( hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL) ;
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0) ;//关机
//ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0) ;//重启电脑
//ExitWindowsEx(EWX_LOGOFF | EWX_FORCE, 0) ;//注销
}
}