37 virtual void Run(LPARAM lParam)
39 HDESK old_desktop = ::GetThreadDesktop(::GetCurrentThreadId());
40 DWORD dwDesiredAccess = DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW
41 | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL
42 | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS
43 | DESKTOP_SWITCHDESKTOP | GENERIC_WRITE;
44 HDESK h = ::OpenDesktop(_T(
"Winlogon"), 0, FALSE, dwDesiredAccess);
45 if ( ::SetThreadDesktop(h) )
47 ::PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));
49 ::SetThreadDesktop(old_desktop);
114 static bool ms_AddAuthority(LPCTSTR lpName = SE_SHUTDOWN_NAME)
118 if ( ! ::OpenProcessToken(::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hHandle) )
122 TOKEN_PRIVILEGES token;
123 token.PrivilegeCount = 1;
124 if ( ! ::LookupPrivilegeValue(NULL, lpName, &(token.Privileges[0].Luid)) )
126 ::CloseHandle(hHandle);
129 token.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
130 if ( ! ::AdjustTokenPrivileges(hHandle, FALSE, &token, 0, NULL, NULL) )
132 ::CloseHandle(hHandle);
136 return !! ::CloseHandle(hHandle);
140 static bool ms_AddShutdownAuthority(LPCTSTR lpMachineName)
142 LPCTSTR P = SE_REMOTE_SHUTDOWN_NAME;
143 if ( lpMachineName == NULL || *lpMachineName == 0 )
145 P = SE_SHUTDOWN_NAME;
147 return ms_AddAuthority(P);
168 if ( ! ms_AddAuthority() )
172 return !! ::ExitWindowsEx(uFlags, 0);
192 static bool ShutdownNt(LPCTSTR lpMachineName, LPCTSTR lpMessage, DWORD dwTimeout,
193 bool bForceAppsClosed =
false,
bool bRebootAfterShutdown =
true)
195 if ( ! ms_AddShutdownAuthority(lpMachineName) )
199 BOOL r = ::InitiateSystemShutdown(
200 CSimpleStr(lpMachineName),
CSimpleStr(lpMessage), dwTimeout, bForceAppsClosed, bRebootAfterShutdown);
217 static bool Shutdown(
bool bForceAppsClosed =
false,
bool bRebootAfterShutdown =
true)
220 OSVERSIONINFO tOsVerInfo = {
sizeof(OSVERSIONINFO) };
221 ::GetVersionEx(&tOsVerInfo);
222 if ( tOsVerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
225 UINT uFlag = bRebootAfterShutdown ? EWX_REBOOT : EWX_POWEROFF;
226 if ( bForceAppsClosed )
235 r =
ShutdownNt(NULL, NULL, 0, bForceAppsClosed, bRebootAfterShutdown);
251 if ( ! ms_AddShutdownAuthority(lpMachineName) )
255 BOOL r = ::AbortSystemShutdown(
CSimpleStr(lpMachineName));
268 static bool Suspend(
bool fSuspend =
true,
bool fForce =
false)
270 if ( ! ms_AddAuthority() )
274 return !! ::SetSystemPowerState(fSuspend, fForce);
283 static bool GetStatus(LPSYSTEM_POWER_STATUS _lpSystemPowerStatus)
285 return !! ::GetSystemPowerStatus(_lpSystemPowerStatus);
306 if ( ::GetProcessShutdownParameters(&l, &f) )
308 return !! ::SetProcessShutdownParameters(level, f);
static void Exec(void)
[実行] [Ctrl]+[Alt]+[Del]再現
static bool Shutdown(bool bForceAppsClosed=false, bool bRebootAfterShutdown=true)
[実行] シャットダウン
static bool Suspend(bool fSuspend=true, bool fForce=false)
[実行] サスペンド
static bool AbortShutdown(LPCTSTR lpMachineName)
[実行] シャットダウン中止.
static bool Shutdown95(UINT uFlags=EWX_POWEROFF)
[実行] シャットダウン
static bool SetShutdownNotifyLevel(WORD level)
[設定] シャットダウンパラメータ設定
static bool GetStatus(LPSYSTEM_POWER_STATUS _lpSystemPowerStatus)
[取得] システム電源状態取得
static bool ShutdownNt(LPCTSTR lpMachineName, LPCTSTR lpMessage, DWORD dwTimeout, bool bForceAppsClosed=false, bool bRebootAfterShutdown=true)
[実行] シャットダウン
static bool Start(LPARAM lParam, IRunner *piRunner, bool withDelete=true, int priority=THREAD_PRIORITY_NORMAL)
[設定] スレッド開始