找回密码
 加入
搜索
查看: 1414|回复: 3

简单的进程管理器.au3源码-----关闭不了进程

[复制链接]
发表于 2009-12-28 23:04:48 | 显示全部楼层 |阅读模式
本帖最后由 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[0][0]
  GUICtrlCreateListViewItem($list[$i][0]&"|"&$list[$i][1],$listview1)
next
return $ListView1
endfunc

func proclose()
$pro = stringsplit(GUICtrlRead(GUICtrlRead($listview1)),"|")
if $pro[0] = 2 then
  if ProcessExists($pro[2]) then ProcessClose($pro[2])  ;;runwait(@ComSpec & " /c taskkill /f /t /pid " & $pro[2],"",@sw_hide)
  else
   msgbox(4096,"错误","无法终止进程!")
  EndIf
  sleep(1000)
  if $pro[0] = 2 then
  if ProcessExists($pro[2]) then
  msgbox(4096,"错误","无法终止进程!")
  return
endif
endif
$ListView1 = list()
endfunc
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
func proclose() 这个函数是否有错误...
$pro[0] ,$pro[2] 表示什么意思?,

if $pro[0] = 2 then
  if ProcessExists($pro[2]) then
  msgbox(4096,"错误","无法终止进程!")
return
endif
endif
这是不是多余???

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2009-12-28 23:39:26 | 显示全部楼层
pro[0]代表了数组有效元素
pro[2]代表了进程的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[0][0]
                GUICtrlCreateListViewItem($list[$i][0] & "|" & $list[$i][1], $ListView1)
        Next
        Return $ListView1
EndFunc   ;==>list

Func proclose()
        $pro = StringSplit(GUICtrlRead(GUICtrlRead($ListView1)), "|")
        If $pro[0] >= 2 Then
                If ProcessExists($pro[2]) Then ProcessClose($pro[2]) ;;runwait(@ComSpec & " /c taskkill /f /t /pid " & $pro[2],"",@sw_hide)
        Else
                MsgBox(4096, "错误", "无法终止进程!")
                Return
        EndIf
        Sleep(1000)
        If ProcessExists($pro[2]) Then
                MsgBox(4096, "错误", "无法终止进程!")
                Return
        Else
                list()
        EndIf
EndFunc   ;==>proclose

评分

参与人数 1金钱 +20 贡献 +2 收起 理由
afan + 20 + 2

查看全部评分

 楼主| 发表于 2009-12-29 09:41:40 | 显示全部楼层
谢谢顽固不化会员....
发表于 2009-12-29 20:33:44 | 显示全部楼层
呵呵,对比LZ与顽固代码之后,GUI代码是正确的,但只是结束的条件错误导致无法终止进程!
func proclose() 
$pro = stringsplit(GUICtrlRead(GUICtrlRead($listview1)),"|") 
if $pro[0] = 2 then 
这里面的"="改为">"或">=",条件为真   就能结束掉!
if $pro[0] = 2 then 
  if ProcessExists($pro[2]) then 
  msgbox(4096,"错误","无法终止进程!") 
return 
endif 
endif 
这句代码也有误,“=”应该改为“<” 这样条件为假时,会弹出“错误,无法终止进程”对话框。其实没有这段代码也没事!

func proclose() 这个函数是否有错误...        这个...偶也不懂..55
$pro[0] ,$pro[2] 表示什么意思?,             听顽固的!!!
下面是偶改的代码:
#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[0][0] 
  GUICtrlCreateListViewItem($list[$i][0]&"|"&$list[$i][1],$listview1) 
next 
return $ListView1 
endfunc 

func proclose() 
$pro = stringsplit(GUICtrlRead(GUICtrlRead($listview1)),"|") 
if $pro[0] > 2 then 
  if ProcessExists($pro[2]) then ProcessClose($pro[2])  ;;runwait(@ComSpec & " /c taskkill /f /t /pid " & $pro[2],"",@sw_hide) 
  else 
   msgbox(4096,"错误","无法终止进程!") 
  EndIf 
  sleep(1000)  
$ListView1 = list() 
endfunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 02:15 , Processed in 0.138864 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表