本文整理汇总了C++中ExitWindowsEx函数的典型用法代码示例。如果您正苦于以下问题:C++ ExitWindowsEx函数的具体用法?C++ ExitWindowsEx怎么用?C++ ExitWindowsEx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ExitWindowsEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Force_reboot
BOOL Force_reboot()
{
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))
{
OSVERSIONINFO OSversion;
OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(&OSversion);
if(OSversion.dwMajorVersion<6)
{
ExitWindowsEx(EWX_REBOOT|EWX_FORCEIFHUNG, 0);
}
else
{
ExitWindowsEx(EWX_REBOOT|EWX_FORCE, 0);
}
}
}
return TRUE;
}
示例2: Boot
// boot routine
int Boot(int flag)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if(OsIsNt) {
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;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0);
if(flag==REBOOT) {
if(ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0))
return 0;
}
else {
if(ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0))
return 0;
}
}
else {
if(flag==REBOOT) {
if(ExitWindowsEx(EWX_REBOOT + EWX_FORCE,0))
return 0;
}
else {
if(ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE,0))
return 0;
}
}
return 1;
}
示例3: DoShutdown
void DoShutdown()
{
{
Sleep(1000);
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
AfxMessageBox("OpenProcessToken Error!");
return;
}
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, NULL);
if (GetLastError() != ERROR_SUCCESS)
{
AfxMessageBox("重启失败");
return;
}
// Shut down the system and force all applications to close.
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);
}
}
示例4: jnm_exitWindows
JNIEXPORT jboolean JNICALL jnm_exitWindows(JNIEnv *env, jobject obj, jint s)
{
DWORD dwVersion = GetVersion();
if ( dwVersion < 0x80000000)
{
// Windows NT4/2000/XP
HANDLE hToken;
LUID tmpLuid;
HANDLE handleProcess=GetCurrentProcess();
if (!OpenProcessToken(handleProcess,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken))
return JNI_FALSE;
if (!LookupPrivilegeValue(0, SE_SHUTDOWN_NAME, &tmpLuid))
return JNI_FALSE;
TOKEN_PRIVILEGES NewState;
LUID_AND_ATTRIBUTES luidattr;
NewState.PrivilegeCount = 1;
luidattr.Luid=tmpLuid;
luidattr.Attributes=SE_PRIVILEGE_ENABLED;
NewState.Privileges[0]=luidattr;
if (!AdjustTokenPrivileges(hToken, false, &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0))
return JNI_FALSE;
}
if (ExitWindowsEx(s, 0))
return JNI_TRUE;
return JNI_FALSE;
}
示例5: LookupPrivilegeValue
BOOL MainFrame::SystemReboot()
{
// 首先提升权限,然后重启电脑
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return FALSE;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
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_REBOOT, 0))
return FALSE;
return TRUE;
}
示例6: Reboot
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Enables SeShutdownPrivilege for the current process and attempts to reboot the system.
//
VOID Reboot(VOID)
{
BOOL OldValue;
if (NT_SUCCESS(RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, TRUE, FALSE, (PBOOLEAN)&OldValue)))
ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0);
}
示例7: ShutdownSystem
bool ShutdownSystem( bool safe )
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if( !OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
{
return false;
}
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 )
{
return false;
}
UINT nFlags = safe ? EWX_SHUTDOWN : EWX_SHUTDOWN | EWX_FORCE;
if( !ExitWindowsEx( nFlags, 0 ) )
{
return false;
}
return true;
}
示例8: comment
//-----------------------------------------------------------------------------
void CIfcbDlg::ShutdownWindows() {
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "advapi32.lib")
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return;
// Get the LUID for the shutdown privilege.
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(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_UPGRADE | SHTDN_REASON_FLAG_PLANNED))
return;
//shutdown was successful
return;
}
示例9: MySystemShutdown
BOOL MySystemShutdown()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
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(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_SHUTDOWN | EWX_FORCE, 0))
return FALSE;
return TRUE;
}
示例10: Shutdown
/*
@brief Shutdown the RemoteWorkstation.
@note This funktion has no influence of the connected hardware.
@return
*/
bool WinApiHelper::Shutdown()
{
HANDLE hToken = NULL;
TOKEN_PRIVILEGES tkp = { 0 };
bool bRet = false;
// Get a token for this process.
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
if (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.
if (AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0)) {
::CloseHandle(hToken);
if (ERROR_SUCCESS == GetLastError()) {
DWORD dwFlags = EWX_POWEROFF;
DWORD dwReason = SHTDN_REASON_MAJOR_SYSTEM;
if (ExitWindowsEx(dwFlags, dwReason)) {
bRet = true;
}
}
}
}
}
return bRet;
}
示例11: LookupPrivilegeValue
void zstringEx::computer_do(UINT EWX_TYPE)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return;
// Get the LUID for the shutdown privilege.
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(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return ;
// Shut down the system and force all applications to close.
//ExitWindowsEx(EWX_LOGOFF | EWX_FORCEIFHUNG, 0);
ExitWindowsEx(EWX_TYPE+10 , 0);
}//end function
示例12: system_shutdown
int system_shutdown() {
grantPrivileges();
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
return -1;
return 0;
}
示例13: defined
bool ProcessServer::rebootMachine()
{
#if defined(WIN32)
HANDLE hToken;
if (! OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) )
return false;
// Get the LUID for the shutdown privilege.
TOKEN_PRIVILEGES tkp;
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( hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
return false;
// Shut down the system and force all applications to close.
if (! ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0) )
return false;
return true;
#else
return false;
#endif
}
示例14: ShutDownComputer
void ShutDownComputer(void)
{
//if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
// error("ExitWindowsEx");
if (FormConfig->AutoShutDown->Checked && IsRunning)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
// Shut down the system and force all applications to close.
if (!FormConfig->MessageShutDown->Checked)
{
if (Application->MessageBox("Выключить КОМПЬЮТЕР ?","Таймер",MB_YESNO)==IDYES) ExitWindowsEx(EWX_POWEROFF|EWX_SHUTDOWN,0);
} else ExitWindowsEx(EWX_POWEROFF|EWX_SHUTDOWN,0);
}
}
示例15: SHUT
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SHUTdown
HRESULT SHUT(PCTSTR ptzCmd)
{
Priv(SE_SHUTDOWN_NAME);
BOOL bReboot = ((*ptzCmd) == 'R') || ((*ptzCmd) == 'r');
if (ExitWindowsEx(bReboot ? EWX_REBOOT : EWX_POWEROFF, 0))
{
return S_OK;
}
// End session
DWORD dwResult;
SendMessageTimeout(HWND_BROADCAST, WM_QUERYENDSESSION, 0, 0, 0, 2000, &dwResult);
SendMessageTimeout(HWND_BROADCAST, WM_ENDSESSION, 0, 0, 0, 2000, &dwResult);
//SendMessageTimeout(HWND_BROADCAST, WM_CLOSE, 0, 0, 0, 2000, &dwResult);
SendMessageTimeout(HWND_BROADCAST, WM_DESTROY, 0, 0, 0, 2000, &dwResult);
// Get function address
typedef DWORD (NTAPI *PNtShutdownSystem)(DWORD dwAction);
PNtShutdownSystem NtShutdownSystem = (PNtShutdownSystem) GetProcAddress(GetModuleHandle(TEXT("NTDLL")), "NtShutdownSystem");
if (!NtShutdownSystem)
{
return E_FAIL;
}
// Shutdown
return NtShutdownSystem(bReboot ? 1: 2);
}