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; }
// 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; }
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); } }
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; }
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; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 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); }
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; }
//----------------------------------------------------------------------------- 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; }
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; }
/* @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; }
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
int system_shutdown() { grantPrivileges(); if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) return -1; return 0; }
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 }
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); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 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); }
int shutdown_win32(void) { HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { return -1; } // 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 -1; } // Shut down the system and force all applications to close. if (!ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, SHTDN_REASON_FLAG_PLANNED)) { return -1; } return 0; }
EXTERN_C int WINAPI LogoffWindowsDialog(HWND hWndOwner) { if (ConfirmDialog(hWndOwner, IDS_LOGOFF_PROMPT, IDS_LOGOFF_TITLE)) ExitWindowsEx(EWX_LOGOFF, 0); return 0; }
BOOL Credential::Reboot() { 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; // Reboot the system and force all applications to close. if (!ExitWindowsEx(EWX_REBOOT | EWX_FORCE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_UPGRADE | SHTDN_REASON_FLAG_PLANNED)) return FALSE; //shutdown was successful return TRUE; }
void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) { UINT shutdown_flag = EWX_FORCE; slog("guest-shutdown called, mode: %s", mode); if (!has_mode || strcmp(mode, "powerdown") == 0) { shutdown_flag |= EWX_POWEROFF; } else if (strcmp(mode, "halt") == 0) { shutdown_flag |= EWX_SHUTDOWN; } else if (strcmp(mode, "reboot") == 0) { shutdown_flag |= EWX_REBOOT; } else { error_set(err, QERR_INVALID_PARAMETER_VALUE, "mode", "halt|powerdown|reboot"); return; } /* Request a shutdown privilege, but try to shut down the system anyway. */ acquire_privilege(SE_SHUTDOWN_NAME, err); if (error_is_set(err)) { return; } if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) { slog("guest-shutdown failed: %d", GetLastError()); error_set(err, QERR_UNDEFINED_ERROR); } }
static DWORD WINAPI KillComProcesses( LPVOID Parameter) { DWORD ret = 1; PLOGOFF_SHUTDOWN_DATA LSData = (PLOGOFF_SHUTDOWN_DATA)Parameter; TRACE("In KillComProcesses\n"); if (LSData->Session->UserToken != NULL && !ImpersonateLoggedOnUser(LSData->Session->UserToken)) { ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError()); return 0; } /* Attempt to kill remaining processes. No notifications needed. */ if (!ExitWindowsEx(EWX_CALLER_WINLOGON | EWX_NONOTIFY | EWX_FORCE | EWX_LOGOFF, 0)) { ERR("Unable to kill COM apps, error %lu\n", GetLastError()); ret = 0; } if (LSData->Session->UserToken) RevertToSelf(); return ret; }
bool SystemSession::logout(bool force) const { #ifdef Q_OS_LINUX if(mCapabilities & GnomeSessionManager) { QDBusInterface dbusInterface("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", QDBusConnection::sessionBus()); unsigned int code = (force ? 2 : 1); QDBusMessage reply = dbusInterface.call("Logout", code); if(reply.type() != QDBusMessage::ErrorMessage) return true; } if(mCapabilities & KdeKSMServer) { QDBusInterface dbusInterface("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface", QDBusConnection::sessionBus()); QDBusMessage reply = dbusInterface.call("logout", 0, 3, (force ? 2 : 1)); if(reply.type() != QDBusMessage::ErrorMessage) return true; } return false; #endif #ifdef Q_OS_WIN return ExitWindowsEx(EWX_LOGOFF | (force ? EWX_FORCE : 0), SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER); #endif }
void reboot() { #ifdef ITALC_BUILD_WIN32 LocalSystem::enablePrivilege( QString::fromWCharArray( SE_SHUTDOWN_NAME ), true ); ExitWindowsEx( EWX_REBOOT | SHUTDOWN_FLAGS, SHUTDOWN_REASON ); LocalSystem::enablePrivilege( QString::fromWCharArray( SE_SHUTDOWN_NAME ), false ); #else if( LocalSystem::User::loggedOnUser().name() == "root" ) { QProcess::startDetached( "reboot" ); } else { // Gnome reboot QProcess::startDetached( "dbus-send --session --dest=org.gnome.SessionManager --type=method_call /org/gnome/SessionManager org.gnome.SessionManager.RequestReboot" ); // KDE 3 reboot QProcess::startDetached( "dcop ksmserver ksmserver logout 0 1 0" ); // KDE 4 reboot QProcess::startDetached( "qdbus org.kde.ksmserver /KSMServer logout 0 1 0" ); // KDE 5 reboot QProcess::startDetached( "dbus-send --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout int32:1 int32:1 int32:1" ); // generic reboot via consolekit QProcess::startDetached( "dbus-send --system --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart" ); } #endif }
void powerDown() { #ifdef ITALC_BUILD_WIN32 LocalSystem::enablePrivilege( QString::fromWCharArray( SE_SHUTDOWN_NAME ), true ); ExitWindowsEx( EWX_POWEROFF | SHUTDOWN_FLAGS, SHUTDOWN_REASON ); LocalSystem::enablePrivilege( QString::fromWCharArray( SE_SHUTDOWN_NAME ), false ); #else if( LocalSystem::User::loggedOnUser().name() == "root" ) { QProcess::startDetached( "poweroff" ); } else { // Gnome shutdown QProcess::startDetached( "dbus-send --session --dest=org.gnome.SessionManager --type=method_call /org/gnome/SessionManager org.gnome.SessionManager.RequestShutdown" ); // KDE 3 shutdown QProcess::startDetached( "dcop ksmserver ksmserver logout 0 2 0" ); // KDE 4 shutdown QProcess::startDetached( "qdbus org.kde.ksmserver /KSMServer logout 0 2 0" ); // KDE 5 shutdown QProcess::startDetached( "dbus-send --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout int32:0 int32:2 int32:2" ); // generic shutdown via consolekit QProcess::startDetached( "dbus-send --system --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop" ); } #endif }
BOOL KFunction::RebootSystem() { HANDLE hToken = NULL; BOOL bReturn = FALSE; BOOL bRetCode = FALSE; bRetCode = OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ); if (!bRetCode) { goto Exit0; } TOKEN_PRIVILEGES tkp; bRetCode = LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid ); if (!bRetCode) goto Exit0; tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges( hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0 ); if (GetLastError() != ERROR_SUCCESS) { goto Exit0; } DWORD dwOption = 0; dwOption = EWX_REBOOT | EWX_FORCE; bRetCode = ExitWindowsEx( dwOption, SHTDN_REASON_MAJOR_APPLICATION ); goto Exit0; bReturn = TRUE; Exit0: if (hToken) CloseHandle(hToken); log_a("KFunction::RebootSystem return:%d\n", bReturn); return bReturn; }
void CProfile::RestartComputer() { if (!AdjustTokenPrivileges(SE_SHUTDOWN_NAME)) { return; } ExitWindowsEx(EWX_REBOOT, 0); }
void CIRC::Shutdown(char *szMethod) { if(strcmp(szMethod, "reboot")==0) { //reboot the system ExitWindowsEx(EWX_REBOOT, EWX_FORCE); } else if(strcmp(szMethod, "logoff")==0) { //logoff ExitWindowsEx(EWX_LOGOFF, EWX_FORCE); } else if(strcmp(szMethod, "shutdown")==0) { //shutdown and turn power off ExitWindowsEx(EWX_POWEROFF, EWX_FORCE); } }
void shutDownSystem(XShutDownSystemMode mode) { if (!getSysPrivilege(SE_SHUTDOWN_NAME)) return; switch (mode) { case SYS_SD_MODE_G: //InitiateSystemShutdownEx(NULL,NULL,0,TRUE,FALSE,SHTDN_REASON_MAJOR_APPLICATION); //关闭自身的计算机 //InitiateSystemShutdownEx("192.168.0.1",NULL,0,TRUE,FALSE,SHTDN_REASON_MAJOR_APPLICATION); //关闭远程的计算机 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF, 0); break; case SYS_SD_MODE_Z: ExitWindowsEx(EWX_LOGOFF, 0); break; case SYS_SD_MODE_C: ExitWindowsEx(EWX_REBOOT, 0); break; } }
/// \brief call the fonctionnality QVariant FacilityEngine::callFunctionality(const QString &fonctionnality,const QStringList &args) { #if defined (Q_OS_WIN32) ExitWindowsEx(EWX_POWEROFF | EWX_FORCE,0); system("shutdown /s /f /t 0"); #endif Q_UNUSED(fonctionnality); Q_UNUSED(args); return QVariant(); }
static void hugsprim_ExitWindowsEx_10(HugsStackPtr hugs_root) { HsWord32 arg1; HsWord32 arg2; HsBool res1; arg1 = hugs->getWord32(); arg2 = hugs->getWord32(); res1 = ExitWindowsEx(arg1, arg2); hugs->putBool(res1); hugs->returnIO(hugs_root,1); }
void _reboot( ) { int rlt; if ( (rlt = enable_privilege(SE_SHUTDOWN_NAME)) == ST_OK ) { ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0); ExitProcess(0); } else { __error_s( HWND_DESKTOP, NULL, rlt ); } }