728x90

[펌]

소스 코드

#SingleInstance, Off
#Persistent
#NoTrayIcon
#NoEnv
ListLines, Off
SetBatchLines, -1

Ico = %A_ScriptDir%\TurnOff.ico
Ini = %A_ScriptDir%\TurnOff.ini
Link = http://saury.tistory.com/
Ver = 0.5 Build 20100606

Menu, Tray, UseErrorLevel
Menu, Tray, NoStandard
Menu, Tray, Add, 열기(&O), MenuOpen
Menu, Tray, Add
Menu, Tray, Add, 종료(&X), MenuExit
Menu, Tray, Default, 열기(&O)
Menu, Tray, Icon, % A_IsCompiled ? A_ScriptFullPath : Ico
Menu, Tray, Tip, TurnOff

SettingList = Action|Process|File|MsgType|Message|When|Hour|Minute|Date|Time|Countdown|ExitAfterRun
Loop, Parse, SettingList, |
	IniRead, %A_LoopField%, %Ini%, Settings, %A_LoopField%, %A_Space%
Action := (Action >= 1 && Action <= 11) ? Action : 1
MsgType := (MsgType >= 1 && MsgType <= 5) ? MsgType : 1
When := (When >= 1 && When <= 3) ? When : 1
Hour := (Hour >= 0 && Hour <= 48) ? Hour : 0
Minute := (Minute >= 0 && Minute <= 59) ? Minute : 0
Date := (IsTime(Date) && RegExMatch(Date, "^\d{8}$")) ? Date : A_YYYY . A_MM . A_DD
Time := (IsTime(Date . Time) && RegExMatch(Time, "^\d{6}$")) ? Time : A_Hour . A_Min . "00"
Countdown := (Countdown = 0 || Countdown = 1) ? Countdown : 0
ExitAfterRun := (ExitAfterRun = 0 || ExitAfterRun = 1) ? ExitAfterRun : 1
Menu, File, Add, 설정 저장(&S), MenuSave
Menu, File, Add, 설정 삭제(&R), MenuRemove
Menu, File, Add
Menu, File, Add, 종료(&X), MenuExit
Menu, Help, Add, 정보(&A), MenuAbout
Menu, MenuBar, Add, 파일(&F), :File
Menu, MenuBar, Add, 도움말(&H), :Help
Gui, 1:Margin, 10, 10
Gui, 1:Font, s9, Gulim
Gui, 1:Menu, MenuBar
Gui, 1:Add, GroupBox, xm ym w220 h345, 동작
Gui, 1:Add, Radio, xp+15 yp+25 h15 vAction gRadioAction, 로그 오프(&L)
Gui, 1:Add, Radio, xp y+5 hp gRadioAction, 종료(&D)
Gui, 1:Add, Radio, xp y+5 hp gRadioAction, 다시 시작(&R)
Gui, 1:Add, Radio, xp y+5 hp gRadioAction, 전원 끄기(&P)
Gui, 1:Add, Radio, xp y+5 hp gRadioAction, 대기 모드(&S)
Gui, 1:Add, Radio, xp y+5 hp gRadioAction, 최대 절전 모드(&H)
Gui, 1:Add, Radio, xp y+5 hp gRadioAction, 화면 보호기(&V)
Gui, 1:Add, Radio, xp y+5 hp gRadioAction, 모니터 전원 끄기(&N)
Gui, 1:Add, Radio, xp y+5 hp gRadioAction, 프로세스 종료(&K)
Gui, 1:Add, Radio, xp y+35 hp gRadioAction, 파일 열기(&O)
Gui, 1:Add, Radio, xp y+35 hp gRadioAction, 메시지 박스(&M)
Gui, 1:Add, Edit, xm+15 ym+205 w160 h25 vProcess, %Process%
Gui, 1:Add, Button, x+5 yp+1 w25 h23 gButtonProcess, ...
Gui, 1:Add, Edit, xm+15 y+26 w160 h25 vFile, %File%
Gui, 1:Add, Button, x+5 yp+1 w25 h23 gButtonFile, ...
Gui, 1:Add, DropDownList, xm+145 y+6 w60 h20 r5 AltSubmit Choose%MsgType% vMsgType, 일반|정보|경고|질문|오류
Gui, 1:Add, Edit, xm+15 y+0 w190 h25 vMessage, %Message%
Gui, 1:Add, GroupBox, xm+230 ym w200 h250, 시기
Gui, 1:Add, Radio, xp+15 yp+25 h15 vWhen gRadioWhen, 바로 실행(&I)
Gui, 1:Add, Radio, xp y+5 hp gRadioWhen, 타이머(&T)
Gui, 1:Add, Radio, xp y+45 hp gRadioWhen, 시간 지정(&E)
Gui, 1:Add, Edit, xm+245 ym+65 w40 h25 Center Limit2 Number
Gui, 1:Add, UpDown, 0x80 Range0-48 vHour, %Hour%
Gui, 1:Add, Text, x+5 yp+5 h15, 시간
Gui, 1:Add, Edit, x+10 yp-5 w40 h25 Center Limit2 Number
Gui, 1:Add, UpDown, 0x80 Range0-59 vMinute, %Minute%
Gui, 1:Add, Text, x+5 yp+5 h15, 분 후
Gui, 1:Add, Text, xm+245 ym+130 hp, 날짜:
Gui, 1:Add, DateTime, x+10 yp-5 w100 h25 Choose%Date%%Time% vDate
Gui, 1:Add, Text, xm+245 y+10 h15, 시간:
Gui, 1:Add, DateTime, x+10 yp-5 w100 h25 1 Choose%Date%%Time% vTime, HH:mm':00'
Gui, 1:Add, Text, xm+245 y+10 w170 h15 vClock
Gui, 1:Add, CheckBox, xp y+15 hp Checked%Countdown% vCountdown, 카운트다운 표시(&C)
Gui, 1:Add, CheckBox, xm+245 ym+265 h15 Checked%ExitAfterRun% vExitAfterRun, 실행 후 프로그램 종료
Gui, 1:Add, Button, xm+255 ym+320 w75 h25 Default gButtonOK, 확인
Gui, 1:Add, Button, x+5 yp wp hp gButtonCancel, 취소
GuiControl, 1:, % "Button" . Action + 1, 1
GuiControl, 1:, % "Button" . When + 15, 1
Gosub, RadioAction
Gosub, RadioWhen
Gosub, ClockTimer
SetTimer, ClockTimer, 1000
Gui, 1:Show,, TurnOff
Return

RadioAction:
Gui, 1:Submit, NoHide
GuiControl, % Action = 9 ? "1:Enable" : "1:Disable", Process
GuiControl, % Action = 9 ? "1:Enable" : "1:Disable", Button13
GuiControl, % Action = 10 ? "1:Enable" : "1:Disable", File
GuiControl, % Action = 10 ? "1:Enable" : "1:Disable", Button14
GuiControl, % Action = 11 ? "1:Enable" : "1:Disable", MsgType
GuiControl, % Action = 11 ? "1:Enable" : "1:Disable", Message
Return

RadioWhen:
Gui, 1:Submit, NoHide
GuiControl, % When = 2 ? "1:Enable" : "1:Disable", Edit4
GuiControl, % When = 2 ? "1:Enable" : "1:Disable", Hour
GuiControl, % When = 2 ? "1:Enable" : "1:Disable", Static1
GuiControl, % When = 2 ? "1:Enable" : "1:Disable", Edit5
GuiControl, % When = 2 ? "1:Enable" : "1:Disable", Minute
GuiControl, % When = 2 ? "1:Enable" : "1:Disable", Static2
GuiControl, % When = 3 ? "1:Enable" : "1:Disable", Static3
GuiControl, % When = 3 ? "1:Enable" : "1:Disable", Date
GuiControl, % When = 3 ? "1:Enable" : "1:Disable", Static4
GuiControl, % When = 3 ? "1:Enable" : "1:Disable", Time
GuiControl, % When = 3 ? "1:Enable" : "1:Disable", Clock
GuiControl, % (When = 2 || When = 3) ? "1:Enable" : "1:Disable", Countdown
Return

ButtonProcess:
Gui, 1:+Disabled
Gui, 2:+Owner1 -MinimizeBox
Gui, 2:Margin, 10, 10
Gui, 2:Font, s9, Gulim
Gui, 2:Add, ListBox, xm ym w220 h200 0x100 vProcess gListBoxProcess, % GetProcList()
Gui, 2:Add, Button, xm+65 y+20 w75 h25 g2ButtonOK, 확인
Gui, 2:Add, Button, x+5 yp wp hp g2ButtonCancel, 취소
Gui, 2:Show,, 프로세스 선택
Return

ListBoxProcess:
IfEqual, A_GuiEvent, DoubleClick, Gosub, 2ButtonOK
Return

2ButtonOK:
GuiControlGet, Process, 2:
GuiControl, 1:, Process, %Process%
Gui, 1:-Disabled
Gui, 2:Destroy
Return

2GuiClose:
2GuiEscape:
2ButtonCancel:
Gui, 1:-Disabled
Gui, 2:Destroy
Return

ButtonFile:
Gui, 1:+OwnDialogs
FileSelectFile, File,,, 파일 선택
IfEqual, ErrorLevel, 0, GuiControl, 1:, File, %File%
Return

ClockTimer:
FormatTime, Clock, T12, Time
GuiControl, 1:, Clock, 현재 시간: %Clock%
Return

ButtonOK:
Gui, 1:Submit, NoHide
GuiControlGet, ActStr, 1:, % "Button" . Action + 1, Text
ActStr := RegExReplace(ActStr, "\(&\w\)")
If (When = 1)
{
	Gui, 1:+OwnDialogs
	MsgBox, 0x21, TurnOff, "%ActStr%" 을(를) 실행하시겠습니까?
	IfMsgBox, OK, Gosub, RunAction
}
Else If (When = 2)
{
	If (Hour = 0 && Minute = 0)
	{
		Gui, 1:+OwnDialogs
		MsgBox, 0x30, TurnOff, 시간 지정이 잘못되었습니다. 다시 지정하십시오.
		Return
	}
	Schedule := A_Now
	Schedule += Hour, Hours
	Schedule += Minute, Minutes
	Menu, Tray, Rename, 열기(&O), 중지(&S)
	Menu, Tray, Default, 중지(&S)
	Menu, Tray, Icon
	TrayTip, %ActStr%, %Hour% 시간 %Minute% 분 후에 예약됨,, 17
	SetTimer, RemoveTrayTip, -2000
	SetTimer, SchedTimer, 1000
	Gui, 1:Hide
}
Else If (When = 3)
{
	Schedule := SubStr(Date, 1, 8) . SubStr(Time, 9, 4) . "00"
	Now := A_Now
	Now -= Schedule, Seconds
	If (Now >= 0)
	{
		Gui, 1:+OwnDialogs
		MsgBox, 0x30, TurnOff, 시간 지정이 잘못되었습니다. 다시 지정하십시오.
		Return
	}
	FormatTime, SchedStr, %Schedule%, yyyy-MM-dd HH:mm:ss
	Menu, Tray, Rename, 열기(&O), 중지(&S)
	Menu, Tray, Default, 중지(&S)
	Menu, Tray, Icon
	TrayTip, %ActStr%, %SchedStr% 에 예약됨,, 17
	SetTimer, RemoveTrayTip, -2000
	SetTimer, SchedTimer, 1000
	Gui, 1:Hide
}
Return

RemoveTrayTip:
TrayTip
Return

SchedTimer:
Now := A_Now
Now -= Schedule, Seconds
LeftTime := -Now
If (LeftTime > 0)
{
	LeftHour := LeftTime // 3600
	LeftMin := (LeftTime - LeftHour * 3600) // 60
	LeftSec := LeftTime - LeftHour * 3600 - LeftMin * 60
	IfEqual, When, 2, Menu, Tray, Tip, %ActStr%`n - %Hour% 시간 %Minute% 분 후에 예약됨`n - 남은 시간 : %LeftHour% 시간 %LeftMin% 분 %LeftSec% 초
	Else IfEqual, When, 3, Menu, Tray, Tip, %ActStr%`n - %SchedStr% 에 예약됨`n - 남은 시간 : %LeftHour% 시간 %LeftMin% 분 %LeftSec% 초
	If (LeftTime <= 30 && Countdown = 1)
		TrayTip, %ActStr%, 남은 시간 : %LeftTime% 초,, 17
}
Else If (LeftTime >= -5)
{
	SetTimer, SchedTimer, Off
	IfEqual, Countdown, 1, TrayTip
	Menu, Tray, Rename, 중지(&S), 열기(&O)
	Menu, Tray, Default, 열기(&O)
	Menu, Tray, Tip, TurnOff
	Gosub, RunAction
}
Return

RunAction:
Gui, 1:Submit, NoHide
Sleep, 100
IfEqual, Action, 1, Shutdown, 4
Else IfEqual, Action, 2, Shutdown, 5
Else IfEqual, Action, 3, Shutdown, 6
Else IfEqual, Action, 4, Shutdown, 12
Else If (Action = 5)
	DllCall("powrprof.dll\SetSuspendState", "Int", 0, "Int", 1, "Int", 0) ; Hibernate = 0, ForceCritical = 1, DisableWakeEvent = 0
Else If (Action = 6)
	DllCall("powrprof.dll\SetSuspendState", "Int", 1, "Int", 1, "Int", 0) ; Hibernate = 1, ForceCritical = 1, DisableWakeEvent = 0
Else IfEqual, Action, 7, SendMessage, 0x112, 0xF140, 0,, ahk_class Progman ; WM_SYSCOMMAND = 0x112, SC_SCREENSAVE = 0xF140
Else IfEqual, Action, 8, SendMessage, 0x112, 0xF170, 2,, ahk_class Progman ; WM_SYSCOMMAND = 0x112, SC_MONITORPOWER = 0xF170
Else IfEqual, Action, 9, Process, Close, %Process%
Else IfEqual, Action, 10, Run, %File%,, UseErrorLevel
Else If (Action = 11)
{
	Gui, 1:+OwnDialogs
	IfEqual, Message,, SetEnv, Message, 시간 알림 메시지입니다.
	IfEqual, MsgType, 2, MsgBox, 0x40, TurnOff, %Message%
	Else IfEqual, MsgType, 3, MsgBox, 0x30, TurnOff, %Message%
	Else IfEqual, MsgType, 4, MsgBox, 0x20, TurnOff, %Message%
	Else IfEqual, MsgType, 5, MsgBox, 0x10, TurnOff, %Message%
	Else MsgBox,, TurnOff, %Message%
}
IfEqual, ExitAfterRun, 1, ExitApp
Return

GuiDropFiles:
StringSplit, $, A_GuiEvent, `n
GuiControl, 1:, File, %$1%
GuiControl, 1:, Button11, 1
Gosub, RadioAction
Return

MenuOpen:
IfInString, A_ThisMenuItem, 중지, SetTimer, SchedTimer, Off
Menu, Tray, NoIcon
Gui, 1:Restore
Gui, 1:+LastFound
WinActivate
Return

MenuSave:
Gui, 1:Submit, NoHide
Date := SubStr(Date, 1, 8)
Time := SubStr(Time, 9, 4) . "00"
Loop, Parse, SettingList, |
	IniWrite, % %A_LoopField%, %Ini%, Settings, %A_LoopField%
Return

MenuRemove:
FileDelete, %Ini%
Return

MenuAbout:
Gui, 3:+LastFoundExist
IfWinExist
{
	WinActivate
	Return
}
Gui, 1:+Disabled
Gui, 3:+Owner1 -MinimizeBox
Gui, 3:Margin, 10, 10
Gui, 3:Font, s9, Gulim
Gui, 3:Add, GroupBox, xm ym w260 h155
Gui, 3:Add, Picture, xp+15 yp+25 w32 h32 Icon1, % A_IsCompiled ? A_ScriptFullPath : Ico
Gui, 3:Add, Text, x+23 yp h15, TurnOff
Gui, 3:Add, Text, xp y+5 hp, 자동 종료 프로그램
Gui, 3:Add, Text, xp y+0 hp, 버전: %Ver%
Gui, 3:Font, Underline
Gui, 3:Add, Text, xp y+10 hp cBlue vLink gTextLink, %Link%
Gui, 3:Font, Norm
Gui, 3:Add, Text, xp y+10 hp, Compiler:
Gui, 3:Add, Text, xp y+0 hp, AutoHotkey v%A_AhkVersion%
Gui, 3:Add, Button, xm+185 ym+170 w75 h25 Default g3ButtonClose, 닫기
Gui, 3:Show,, TurnOff 정보
OnMessage(0x20, "WM_MOUSEMOVE")
OnMessage(0x200, "WM_MOUSEMOVE")
Return

TextLink:
MouseGetPos,,,, hCtrlD, 2
KeyWait, LButton
MouseGetPos,,,, hCtrlU, 2
IfEqual, hCtrlU, %hCtrlD%, Run, %Link%,, UseErrorLevel
Return

3GuiClose:
3GuiEscape:
3ButtonClose:
Gui, 1:-Disabled
Gui, 3:Destroy
Return

GuiClose:
GuiEscape:
MenuExit:
ButtonCancel:
ExitApp

WM_MOUSEMOVE(wParam, lParam, uMsg)
{
	Static Hover, HandCur, OldCur
	IfNotEqual, A_Gui, 3, Return
	If (uMsg = 0x20 && Hover = 1)
		Return, 1
	Else If (uMsg = 0x200)
	{
		If (A_GuiControl = "Link")
		{
			If (Hover = "")
			{
				HandCur := DllCall("LoadCursor", "UInt", 0, "UInt", 32649)
				Hover = 1
			}
			OldCur := DllCall("SetCursor", "UInt", HandCur)
		}
		Else If (Hover = 1)
		{
			DllCall("SetCursor", "UInt", OldCur)
			Hover =
		}
	}
}

IsTime(Time)
{
	If Time Is Time
		Return, 1
	Return, 0
}

GetProcList()
{
	Process, Exist
	h := DllCall("OpenProcess", "UInt", 0x400, "Int", 0, "UInt", ErrorLevel) ; PROCESS_QUERY_INFORMATION = 0x400
	DllCall("advapi32.dll\OpenProcessToken", "UInt", h, "UInt", 32, "UIntP", t) ; TOKEN_ADJUST_PRIVILEGES = 32
	VarSetCapacity(ti, 16, 0)
	NumPut(1, ti, 0)
	DllCall("advapi32.dll\LookupPrivilegeValueA", "UInt", 0, "Str", "SeDebugPrivilege", "Int64P", luid)
	NumPut(luid, ti, 4, "Int64")
	NumPut(2, ti, 12) ; SE_PRIVILEGE_ENABLED = 2
	DllCall("advapi32.dll\AdjustTokenPrivileges", "UInt", t, "Int", 0, "UInt", &ti, "UInt", 0, "UInt", 0, "UInt", 0)
	DllCall("CloseHandle", "UInt", h)
	hModule := DllCall("LoadLibrary", "Str", "psapi.dll")
	s := VarSetCapacity(a, 4096, 0)
	DllCall("psapi.dll\EnumProcesses", "UInt", &a, "UInt", s, "UIntP", r)
	Loop, % r // 4
	{
		pid := NumGet(a, A_Index * 4)
		h := DllCall("OpenProcess", "UInt", 0x410, "Int", 0, "UInt", pid) ; PROCESS_VM_READ = 0x10 | PROCESS_QUERY_INFORMATION = 0x400
		VarSetCapacity(n, s, 0)
		e := DllCall("psapi.dll\GetModuleBaseNameA", "UInt", h, "UInt", 0, "Str", n, "UInt", s)
		DllCall("CloseHandle", "UInt", h)
		If (n && e)
			l .= l ? "|" . n : n
	}
	DllCall("FreeLibrary", "UInt", hModule)
	Return, l
}

 

TurnOff.ahk
0.01MB

728x90

'AutoHotKey' 카테고리의 다른 글

CoHelper.ahk  (0) 2023.08.28
COM.ahk  (0) 2023.08.28
[GUI] Countdown Timer  (0) 2023.08.27
[GUI] SysMeter v0.6 by jNizM  (0) 2023.08.19
[GUI] skinsharp  (0) 2023.08.19

+ Recent posts