Если реагирует на хоткей, то считай что и не завис.
Насчёт обработки ошибок определённых строк, есть TRY. Для всех ошибок Com объектов в скрипте, есть ComObjError(false).
Ну и по случаю, давно хотел себе сделать простенький таскман анк скриптов.
; http://forum.script-coding.com/viewtopic.php?pid=83407#p83407
#SingleInstance Force
#NoTrayIcon
#NoEnv
ListLines Off
SetBatchLines -1
Menu, Tray, UseErrorLevel
Menu, Tray, Icon, Shell32.dll, 262
IgnoreList =
LimitRow := 12, Process := [], Count := 0
Query := "SELECT * FROM Win32_Process WHERE Caption = 'AutoHotkey.exe' AND ProcessId != " DllCall("GetCurrentProcessId")
WMI := ComObjGet("winmgmts:").ExecQuery(Query)
For Proc In WMI
{
RegExMatch(Proc.CommandLine, "Si).*""(?<Folder>.*?:.*)\\(?<Name>.*)\.ahk""", _)
Date := SubStr(Proc.CreationDate, 1, 14)
FormatTime, Time, %Date%, HH:mm:ss ; dd-MM
If _Name In %IgnoreList%
Continue
Process[A_Index] := [_Name, Time, _Folder, Proc.ProcessId], ++Count
}
DeleteDummyIcons()
If !Count
{
MsgBox, 4149, AhkTask, AutoHotkey process not found!
IfMsgBox Retry
Reload
ExitApp
}
RC := Count > LimitRow ? LimitRow : Count
Gui, Font, s10
Gui, Margin, 0, 0
Gui, -DPIScale +AlwaysOnTop
Gui, Add, ListView, AltSubmit Grid vLV hwndhLV BackgroundE8E8FF R%RC%, Name|TimeCreate|Folder|PID
Gui, Add, Text, y+2 vBut1 Border +0x201 gClose, Close
Gui, Add, Text, x+0 vBut2 Border +0x201 hp gOpenFolder, In Folder
Gui, Add, Text, xm y+2 vBut3 Border +0x201 hp gSelectAll, Select All
Gui, Add, Text, x+0 vBut4 Border +0x201 hp gReload, Reload
For k, v in Process
LV_Add("", v[1], v[2], v[3], v[4])
GuiControl, -Redraw, LV
Loop % LV_GetCount("Col")
LV_ModifyCol(A_Index, "AutoHdr")
LV_InsertCol(LV_GetCount("Col")+1), LV_ModifyCol(LV_GetCount("Col")-1, "AutoHdr"), LV_DeleteCol(LV_GetCount("Col"))
LV_Modify(1, "Select"), LV_ModifyCol(2, "SortDesc")
GuiControl, +Redraw, LV
Loop % 4 + (Width := 0)
{
SendMessage, 4125, A_Index - 1, 0, , ahk_id %hLV%
Width += ErrorLevel
}
Width += (Count > LimitRow ? 26 : 4)
GuiControl, Move, LV, % "w" Width
Loop 4
GuiControl, Move, But%A_Index%, % "w" Width // 2 " x" Width // 2 * (Mod(A_Index+1, 2))
Gui, Show, % "xCenter y100 w" Width, AhkTask
OnMessage(0x203, "WM_LBUTTONDBLCLK")
Return
Close:
Critical
Loop % S := LV_GetCount("S")
{
sRow := LV_GetNext()
LV_GetText(sPID, sRow, 4)
Process, Close, %sPID%
Process, WaitClose, %sPID%, 1
If !ErrorLevel
LV_Delete(sRow), DeleteDummyIcons()
}
If S = 1
LV_Modify(LV_GetCount() < sRow ? LV_GetCount() : sRow, "Select")
Return
OpenFolder:
Loop % LV_GetCount("S") + (sRow := 0)
{
sRow := LV_GetNext(sRow)
LV_GetText(sFolder, sRow, 3)
LV_GetText(sName, sRow, 1)
SelectFilePath(sFolder "\" sName ".ahk")
}
Return
SelectAll:
LV_Modify(0, "Select")
Return
Reload:
Reload
Return
GuiClose:
GuiEscape:
ExitApp
WM_LBUTTONDBLCLK() {
If InStr(A_GuiControl, "But")
{
If A_GuiControl = But1
SetTimer, Close, -1
Return 0
}
}
SelectFilePath(FilePath) {
SplitPath, FilePath,, Dir
for window in ComObjCreate("Shell.Application").Windows
{
ShellFolderView := window.Document
Try If ((Folder := ShellFolderView.Folder).Self.Path != Dir)
Continue
Catch
Continue
for item in Folder.Items
{
If (item.Path != FilePath)
Continue
ShellFolderView.SelectItem(item, 1|4|8|16)
WinActivate, % "ahk_id" window.hwnd
Return
}
}
Run, %A_WinDir%\explorer.exe /select`, "%FilePath%", , UseErrorLevel
}