BOOL CTestAllView::OnFshutdown()
{
// TODO: Add your control notification handler code here
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
// OpenProcessToken() 这个函数的作用是打开一个进程的访问令牌
// GetCurrentProcess() 函数的作用是得到本进程的句柄
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
// LookupPrivilegeValue() 的作用是修改进程的权限
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; //one privilege to set 赋给本进程特权
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
// AdjustTokenPrivileges()的作用是通知Windows NT修改本进程的权利
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0)) //参数在这里设置。 强行退出WINDOWS。
return FALSE;
return TRUE;
}
{
// TODO: Add your control notification handler code here
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
// OpenProcessToken() 这个函数的作用是打开一个进程的访问令牌
// GetCurrentProcess() 函数的作用是得到本进程的句柄
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
// LookupPrivilegeValue() 的作用是修改进程的权限
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; //one privilege to set 赋给本进程特权
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
// AdjustTokenPrivileges()的作用是通知Windows NT修改本进程的权利
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0)) //参数在这里设置。 强行退出WINDOWS。
return FALSE;
return TRUE;
}