電源をオフにするモジュールを作ってみました。
#ifndef __GM_EXIT_WINDOWS__
#define global __GM_EXIT_WINDOWS__
#include "kernel32.as"
#include "advapi32.as"
#include "user32.as"
#uselib "PowrProf.dll"
#func global SetSuspendState "SetSuspendState" int, int, int
#module
#const TRUE 1
#const FALSE 0
#const NULL 0
#const TOKEN_ADJUST_PRIVILEGES 0x20
#const SIZE_LUID 8
#const SIZE_LUID_AND_ATTRIBUTES 12
#const SIZE_TOKEN_PRIVILEGES 16
#define SE_SHUTDOWN_NAME "SeShutdownPrivilege"
#const SE_PRIVILEGE_ENABLED 0x02
#const PRIVILEGE_COUNT 1
#const EWX_FORCE 0x00000004
#const EWX_LOGOFF 0
#const EWX_SHUTDOWN 1
#const EWX_REBOOT 2
#const EWX_POWEROFF 8
#const EWX_HYBRID_SHUTDOWN 0x00400000
#define win_restart win_reboot
#deffunc _adjust_privilege
GetCurrentProcess
hproc = stat
htoken = 0
OpenProcessToken hproc, TOKEN_ADJUST_PRIVILEGES, varptr(htoken)
dim luid, SIZE_LUID / 4
dim luid_and_attributes, SIZE_LUID_AND_ATTRIBUTES / 4
dim token_privileges, SIZE_TOKEN_PRIVILEGES / 4
LookupPrivilegeValue NULL, SE_SHUTDOWN_NAME, varptr(luid)
luid_and_attributes = luid(0), luid(1), SE_PRIVILEGE_ENABLED
token_privileges = PRIVILEGE_COUNT, luid_and_attributes(0), luid_and_attributes(1), luid_and_attributes(2)
AdjustTokenPrivileges htoken, FALSE, varptr(token_privileges), 0, NULL, NULL
CloseHandle htoken
return
/*
* 指定の方法でWindowsを終了
*/
#deffunc _exit_win int ewx_type_
_adjust_privilege
ExitWindowsEx ewx_type_,0
return
/*
* Windowsをサスペンド(スリープ)または休止(ハイバネート)
*/
#deffunc _suspend_win int flag_hiberbate_
_adjust_privilege
SetSuspendState flag_hiberbate_, FALSE, FALSE
return
//ログオフ(サインアウト)
#deffunc win_logoff
_exit_win EWX_LOGOFF,NULL
return
#deffunc win_logoff_force//強制
_exit_win EWX_LOGOFF|EWX_FORCE
return
//シャットダウン
#deffunc win_shutdown
_exit_win EWX_SHUTDOWN,NULL
return
#deffunc win_shutdown_force//強制
_exit_win EWX_SHUTDOWN|EWX_FORCE
return
//シャットダウン(高速スタートアップ)
#deffunc win_shutdown_hybrid
_exit_win EWX_HYBRID_SHUTDOWN,NULL
return
#deffunc win_shutdown_hybrid_force//強制
_exit_win EWX_HYBRID_SHUTDOWN|EWX_FORCE
return
//再起動
#deffunc win_reboot
_exit_win EWX_REBOOT,NULL
return
#deffunc win_reboot_force//強制
_exit_win EWX_REBOOT|EWX_FORCE
return
//電源オフ
#deffunc win_poweroff
_exit_win EWX_POWEROFF,NULL
return
#deffunc win_poweroff_force//強制
_exit_win EWX_POWEROFF|EWX_FORCE
return
//スリープ
#deffunc win_sleep
_suspend_win FALSE
return
//サスペンド
#deffunc win_suspend
_suspend_win FALSE
return
//休止状態
#deffunc win_hibernate
_suspend_win TRUE
return
#global
#endif
//モジュールここまで
#packopt hide 1
screen 0,300,150
title "電源"
objsize 300,30
button "シャットダウン",*shutdown
button "シャットダウン(高速スタートアップ)",*shutdown_hybrid
button "再起動",*reboot
button "スリープ",*_sleep
button "休止状態",*hibernate
stop
*shutdown
win_shutdown
end
*shutdown_hybrid
win_shutdown_hybrid
end
*reboot
win_reboot
end
*_sleep
win_sleep
end
*hibernate
win_hibernate
end