简单的进程管理器.au3源码-----关闭不了进程
本帖最后由 oneuu 于 2009-12-29 09:45 编辑如题.
源码:
#notrayicon
#Include <GUIConstants.au3>
dim $ListView1
GUICreate("简单的进程管理器", 257, 364)
$Button1 = GUICtrlCreateButton("结束进程", 8, 328, 105, 25)
$Button2 = GUICtrlCreateButton("刷新列表", 144, 328, 105, 25)
$ListView1 = list()
GUISetState(@SW_SHOW)
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
proclose()
Case $msg = $Button2
$ListView1 = list()
EndSelect
WEnd
Exit
func list()
if $ListView1 then GUICtrlDelete($ListView1)
$list = ProcessList()
$ListView1 = GUICtrlCreateListView("进程名 |PID ", 8, 8, 241, 305)
for $i = 1 to $list
GUICtrlCreateListViewItem($list[$i]&"|"&$list[$i],$listview1)
next
return $ListView1
endfunc
func proclose()
$pro = stringsplit(GUICtrlRead(GUICtrlRead($listview1)),"|")
if $pro = 2 then
if ProcessExists($pro) then ProcessClose($pro);;runwait(@ComSpec & " /c taskkill /f /t /pid " & $pro,"",@sw_hide)
else
msgbox(4096,"错误","无法终止进程!")
EndIf
sleep(1000)
if $pro = 2 then
if ProcessExists($pro) then
msgbox(4096,"错误","无法终止进程!")
return
endif
endif
$ListView1 = list()
endfunc
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
func proclose() 这个函数是否有错误...
$pro ,$pro 表示什么意思?,
if $pro = 2 then
if ProcessExists($pro) then
msgbox(4096,"错误","无法终止进程!")
return
endif
endif
这是不是多余??? pro代表了数组有效元素
pro代表了进程的PID
确实存在错误,修正如下:#NoTrayIcon
#include <GUIConstants.au3>
Dim $ListView1
GUICreate("简单的进程管理器", 257, 364)
$Button1 = GUICtrlCreateButton("结束进程", 8, 328, 105, 25)
$Button2 = GUICtrlCreateButton("刷新列表", 144, 328, 105, 25)
$ListView1 = list()
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
proclose()
Case $msg = $Button2
$ListView1 = list()
EndSelect
WEnd
Exit
Func list()
If $ListView1 Then GUICtrlDelete($ListView1)
$list = ProcessList()
$ListView1 = GUICtrlCreateListView("进程名 |PID ", 8, 8, 241, 305)
For $i = 1 To $list
GUICtrlCreateListViewItem($list[$i] & "|" & $list[$i], $ListView1)
Next
Return $ListView1
EndFunc ;==>list
Func proclose()
$pro = StringSplit(GUICtrlRead(GUICtrlRead($ListView1)), "|")
If $pro >= 2 Then
If ProcessExists($pro) Then ProcessClose($pro) ;;runwait(@ComSpec & " /c taskkill /f /t /pid " & $pro,"",@sw_hide)
Else
MsgBox(4096, "错误", "无法终止进程!")
Return
EndIf
Sleep(1000)
If ProcessExists($pro) Then
MsgBox(4096, "错误", "无法终止进程!")
Return
Else
list()
EndIf
EndFunc ;==>proclose 谢谢顽固不化会员.... 呵呵,对比LZ与顽固代码之后,GUI代码是正确的,但只是结束的条件错误导致无法终止进程!func proclose()
$pro = stringsplit(GUICtrlRead(GUICtrlRead($listview1)),"|")
if $pro = 2 then 这里面的"="改为">"或">=",条件为真 就能结束掉!if $pro = 2 then
if ProcessExists($pro) then
msgbox(4096,"错误","无法终止进程!")
return
endif
endif
这句代码也有误,“=”应该改为“<” 这样条件为假时,会弹出“错误,无法终止进程”对话框。其实没有这段代码也没事!
func proclose() 这个函数是否有错误... 这个...偶也不懂..55
$pro ,$pro 表示什么意思?, 听顽固的!!!
下面是偶改的代码:#notrayicon
#Include <GUIConstants.au3>
dim $ListView1
GUICreate("简单的进程管理器", 257, 364)
$Button1 = GUICtrlCreateButton("结束进程", 8, 328, 105, 25)
$Button2 = GUICtrlCreateButton("刷新列表", 144, 328, 105, 25)
$ListView1 = list()
GUISetState(@SW_SHOW)
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
proclose()
Case $msg = $Button2
$ListView1 = list()
EndSelect
WEnd
Exit
func list()
if $ListView1 then GUICtrlDelete($ListView1)
$list = ProcessList()
$ListView1 = GUICtrlCreateListView("进程名 |PID ", 8, 8, 241, 305)
for $i = 1 to $list
GUICtrlCreateListViewItem($list[$i]&"|"&$list[$i],$listview1)
next
return $ListView1
endfunc
func proclose()
$pro = stringsplit(GUICtrlRead(GUICtrlRead($listview1)),"|")
if $pro > 2 then
if ProcessExists($pro) then ProcessClose($pro);;runwait(@ComSpec & " /c taskkill /f /t /pid " & $pro,"",@sw_hide)
else
msgbox(4096,"错误","无法终止进程!")
EndIf
sleep(1000)
$ListView1 = list()
endfunc
页:
[1]