指定した時刻にスタンバイや休止状態から復帰させるスクリプトです。SetWaitTimer で復帰時刻を指定してください。現在時刻より前ですと復帰しませんのでご注意を。また SetPrivileges で一度だけ権限を昇格させる必要があります。
指定した時刻にスタンバイや休止状態から復帰させるスクリプトです。SetWaitTimer で復帰時刻を指定してください。現在時刻より前ですと復帰しませんのでご注意を。また SetPrivileges で一度だけ権限を昇格させる必要があります。
// http://web.archive.org/web/20060511161900/http://www.apple.ac/~namasoft/codebank/delphi2.php#include "kernel32.as"#include "user32.as"#module _st_#uselib "advapi32.dll"#func OpenProcessToken "OpenProcessToken" int, int, var#func LookupPrivilegeValue "LookupPrivilegeValueA" sptr, sptr, var#func AdjustTokenPrivileges "AdjustTokenPrivileges" int, int, var, int, int, int#uselib "powrprof.dll"#func SetSuspendState "SetSuspendState" int,int,int#define EWX_LOGOFF 0 // ログオフ#define EWX_SHUTDOWN 1 // シャットダウン#define EWX_REBOOT 2 // 再起動#define EWX_FORCE 4 // 強制#define EWX_POWEROFF 8 // 電源を切る#define TOKEN_QUERY 0x08#define TOKEN_ADJUST_PRIVILEGES 0x20#define SE_SHUTDOWN_NAME "SeShutdownPrivilege"#define SE_PRIVILEGE_ENABLED 0x02#deffunc SetWaitTimer int y, int m, int d, int h, int min, int sif hTimer != 0 : return -1dim systime, 4dim filetime, 2dim utctime, 2wpoke systime, 0, ywpoke systime, 2, mwpoke systime, 6, dwpoke systime, 8, hwpoke systime, 10, minwpoke systime, 12, swpoke systime, 14, 0SystemTimeToFileTime varptr(systime), varptr(filetime)LocalFileTimeToFileTime varptr(filetime), varptr(utctime)CreateWaitableTimer 0, 0, 0hTimer = statSetWaitableTimer hTimer, varptr(utctime), 0, 0, 0, 1return#deffunc SetSystemPower int mode, int forcef = 0if force == 1 : f = EWX_FORCEswitch modecase 0// ログオフExitWindowsEx (f + EWX_LOGOFF), 0swbreakcase 1// シャットダウンExitWindowsEx (f + EWX_SHUTDOWN), 0swbreakcase 2// 再起動ExitWindowsEx (f + EWX_REBOOT), 0swbreakcase 3// 電源を切るExitWindowsEx (f + EWX_POWEROFF), 0swbreakcase 4// 休止状態SetSuspendState 1, 0, 0swbreakcase 5// スタンバイSetSuspendState 0, 0, 0swbreakcase 6// 休止状態(自動復帰しない様子)SetSystemPowerState 0, forceswbreakcase 7// スタンバイ(自動復帰しない様子)SetSystemPowerState 1, forceswbreakswendreturn stat// 待機用#deffunc SetWaitForSingleObjectif hTimer == 0 : return -1WaitForSingleObject hTimer, 0xFFFFFFFFSetThreadExecutionState 0x00000001 | 0x00000002CloseHandle hTimerif stat != 0 : hTimer = 0return 0// タイマーのクリア#deffunc ClearTimerif hTimer == 0 : return -1CloseHandle hTimerif stat != 0 : hTimer = 0 : return 0return -1// 権限昇格#deffunc SetPrivilegesdim Luid, 2dim tokenNew, 16dim tokenPre, 16GetCurrentProcesshProcess = statOpenProcessToken hProcess, TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, hTokenif stat == 0 : return -1LookupPrivilegeValue 0, SE_SHUTDOWN_NAME, Luidif stat == 0 : return -2tokenNew(0) = 1memcpy tokenNew(1), Luid, 8tokenNew(3) = SE_PRIVILEGE_ENABLEDAdjustTokenPrivileges hToken, 0, tokenNew, 16, varptr(tokenPre), varptr(ret)if stat == 0 : return -3return 0#global// サンプル// 一度は権限昇格させるSetPrivileges// 復帰時刻を指定// 以下の例は 2012年1月14日 0時21分0秒 に復帰させるために指定// 現在時刻より前の時刻ですと復帰しませんので注意!SetWaitTimer 2012, 1, 14, 0, 21, 0// スタンバイしてみる; 第1引数のパラメータ; 0 = ログオフ; 1 = シャットダウン; 2 = 再起動; 3 = 電源を切る; 4 = 休止状態; 5 = スタンバイ; 6 = 休止状態(自動復帰しない); 7 = スタンバイ(自動復帰しない); 第2引数は強制するかどうか?; 1 を指定すると強制モード、0 だと強制しないSetSystemPower 5, 1// SetSystemPower を実行後↓処理してくださいSetWaitForSingleObject// タイマーのクリア(正常に処理された場合は必要なし);ClearTimerdialog "復帰!"