AHK 进程管理

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: AHK 进程管理

Re: AHK 进程管理

by hitman » 13 Apr 2017, 22:05

thx,good!

Re: AHK 进程管理

by pk23 » 26 Feb 2017, 21:36

感谢,小巧好用

Re: AHK 进程管理

by et2010 » 26 Jan 2017, 08:12

@tmplinshi 感谢你的快速回复,另存为UTF-8(with BOM)后问题已解决。

Re: AHK 进程管理

by tmplinshi » 26 Jan 2017, 03:04

@Guest 文件要保存为 UTF-8 (含BOM)

Re: AHK 进程管理

by Guest » 25 Jan 2017, 22:49

感谢分享!但是我运行时报错:
AhkScriptManager.ahk (32) : ==> Functions cannot contain functions.
Specifically: RefreshList()

Re: AHK 进程管理

by huyaowen » 27 Oct 2016, 00:22

试过好几个都太啰嗦,这个好。简单干练。

AHK 进程管理

by tmplinshi » 26 Oct 2016, 23:29

AhkScriptManager.png
AhkScriptManager.png (10.81 KiB) Viewed 314 times

Code: Select all

#NoEnv
#NoTrayIcon
#SingleInstance Force
SetBatchLines -1
DetectHiddenWindows On

CreateGUI()
CreateMenu()
RefreshList()
return

GuiClose:
GuiEscape:
ExitApp

CreateGUI() {
	global
	Gui, Font, s10, 微软雅黑
	Gui, Add, ListView, xm w700 r10 Grid HwndHLV gLvEvent AltSubmit, 文件名|文件路径|PID
	Loop, Parse, % "退出|重启|暂停|暂停热键|结束进程", |
		Gui, Add, Button, % (A_Index=1 ? "" : "x+40") . " Disabled gExecMenu", %A_LoopField%
	Gui, Add, Button, x+100 gReloadAll, 重启全部
	Gui, Add, Button, x+55 gRefreshList vBtnRefresh, 刷新列表
	Gui, Show,, AHK 进程管理 v1.05
}

CreateMenu() {
	Loop, Parse, % "退出|重启|暂停|暂停热键||结束进程", |
		Menu, lvMenu, Add, % A_LoopField, MenuHandler
}

RefreshList() {
	static selfPID := DllCall("GetCurrentProcessId")

	LV_Delete()

	WinGet, id, List, ahk_class AutoHotkey
	Loop, %id% {
		this_id := id%A_Index%
		WinGet, this_pid, PID, ahk_id %this_id%

		if (this_pid != selfPID)
		{
			WinGetTitle, this_title, ahk_id %this_id%
			fPath := RegExReplace(this_title, " - AutoHotkey v[\d.]+$")
			SplitPath, fPath, fName
			
			LV_Add("", fName, fPath, this_pid)
		}
	}

	LV_ModifyCol()
	LV_ModifyCol(1, "Sort")
	GuiControl,, BtnRefresh, 刷新列表
}

GuiContextMenu(GuiHwnd, CtrlHwnd) {
	global HLV
	if (CtrlHwnd = HLV) && LV_GetNext() {
		Menu, lvMenu, Show
	}
}

MenuHandler(ItemName) {
	static cmd := {重启: 65303, 暂停热键: 65305, 暂停: 65306, 退出: 65307}
	static WM_COMMAND := 0x111

	if (ItemName = "结束进程") {
		for i, obj in GetSelectedInfo()
			Process, Close, % obj.pid
	} else {
		for i, obj in GetSelectedInfo()
			PostMessage, WM_COMMAND, % cmd[ItemName],,, % obj.path " ahk_pid " obj.pid
	}

	if (ItemName = "重启") {
		GuiControl,, BtnRefresh, 刷新中...
		SetTimer, RefreshList, -3000
	} else if (ItemName ~= "退出|结束")
		SetTimer, RefreshList, -300
}

GetSelectedInfo() {
	RowNum := 0, arr := []
	while, RowNum := LV_GetNext(RowNum) {
		LV_GetText(path, RowNum, 2)
		LV_GetText(pid, RowNum, 3)
		arr.push( {pid: pid, path: path} )
	}
	return arr
}

LvEvent() {
	if !(A_GuiEvent == "I")
		return

	GuiControlGet, isEnabled, Enabled, 退出
	nSelected := LV_GetCount("Selected")
	if !(isEnabled && nSelected) || !(!isEnabled && !nSelected)
	{
		Loop, Parse, % "退出|重启|暂停|暂停热键|结束进程", |
			GuiControl, % "Enabled" !!nSelected, %A_LoopField%
	}
}

ExecMenu() {
	MenuHandler(A_GuiControl)
}

ReloadAll() {
	Loop, % LV_GetCount()
	{
		LV_GetText(path, A_Index, 2)
		LV_GetText(pid, A_Index, 3)
		PostMessage, 0x111, 65303,,, % path " ahk_pid " pid
	}
}
类似工具: 脚本调试辅助器

Top