| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2244 人关注过本帖
标题:一个简单的进程管理程序
只看楼主 加入收藏
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
 问题点数:0 回复次数:12 
一个简单的进程管理程序

效果图

窗体里放一个ListView和两个按钮

Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Const SW_HIDE = 0 Private Const SW_RESTORE = 9 Private Const SW_SHOW = 5

Private Const TH32CS_SNAPPROCESS = &H2 Private Const TH32CS_SNAPheaplist = &H1 Private Const TH32CS_SNAPthread = &H4 Private Const TH32CS_SNAPmodule = &H8 Private Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule Private Const MAX_PATH As Integer = 260 Private Const PROCESS_TERMINATE = &H1

Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type

Private Sub command1_Click() Dim i As Long Dim proc As PROCESSENTRY32 Dim snap As Long Dim exename As String lvw.ListItems.Clear ': 清空所有内容 snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) ':获得进程“快照”的句柄 proc.dwSize = Len(proc) theloop = ProcessFirst(snap, proc) ':获取第一个进程,并得到其返回值 i = 0 While theloop <> 0 ':当返回值非零时继续获取下一个进程 exename = proc.szExeFile ret = lvw.ListItems.Add(, "first" & CStr(i), exename) ':将进程名添加到第一项中 lvw.ListItems("first" & CStr(i)).SubItems(1) = proc.th32ProcessID ':将进程ID添加到第二项中 i = i + 1 theloop = ProcessNext(snap, proc) Wend CloseHandle snap ':关闭进程“快照”句柄 End Sub Private Sub Command2_Click() Dim i As Long hand = OpenProcess(PROCESS_TERMINATE, True, CLng(lvw.SelectedItem.SubItems(1))) ':获取进程句柄 TerminateProcess hand, 0 ':关闭进程 Call command1_Click ':调用查看进程来刷新进程列表 End Sub

Private Sub Command3_Click() hand = OpenProcess(PROCESS_TERMINATE, True, CLng(lvw.SelectedItem.SubItems(1))) ':获取进程句柄 ShowWindow hand, SW_SHOW End Sub

Private Sub Command4_Click() hand = OpenProcess(PROCESS_TERMINATE, True, CLng(lvw.SelectedItem.SubItems(1))) ':获取进程句柄 ShowWindow hand, SW_HIDE Text1.Text = hand End Sub

Private Sub Form_Load() Dim header As ColumnHeader lvw.View = lvwReport lvw.ColumnHeaders.Clear Set header = lvw.ColumnHeaders.Add(, "first", "进程", 4000) ':设置ListView中项目的宽度,读者也可自行设置 Set header = lvw.ColumnHeaders.Add(, "second", "ID", 1400) lvw.Refresh End Sub

[此贴子已经被作者于2004-05-20 17:53:56编辑过]

搜索更多相关主题的帖子: 管理程序 进程 
2004-04-21 09:47
pigpigpig
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2004-4-18
收藏
得分:0 
有点难度。哈哈。

没有做不到的,只有想不到的!
2004-04-21 18:51
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
################

天津网站建设 http://www./
2004-05-20 18:10
eudigss
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2004-5-20
收藏
得分:0 
谢谢  爱情
2004-05-20 19:11
随意魔
Rank: 1
等 级:新手上路
帖 子:184
专家分:0
注 册:2004-5-13
收藏
得分:0 

伤心王心,你还真棒的:)


.-_-.曾经拥有.足以泪流.-_-.
2004-05-20 20:56
不翼而飞
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2004-6-3
收藏
得分:0 
555555555555
看不懂      。。。。。。。。。。。。顶
2004-06-03 17:06
ant3000
Rank: 1
等 级:新手上路
帖 子:188
专家分:0
注 册:2004-6-7
收藏
得分:0 
呵呵,谢谢   等我研究一下
2004-06-11 02:11
zhiye_xg
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2004-9-2
收藏
得分:0 

唉~~~~~~~~~~~~~~~

资历不够呀!暂时还看不懂,如能出一份详细的说明让我们这些菜鸟们学学那就在好不过了。

不过怎么说也要顶一下

2004-09-02 20:25
iaishina_2
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2004-9-27
收藏
得分:0 

耍我啊? 我是才鸟


2004-09-29 14:50
lvlink
Rank: 1
等 级:新手上路
帖 子:82
专家分:0
注 册:2004-9-20
收藏
得分:0 

看不懂

2004-10-14 19:52
快速回复:一个简单的进程管理程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017940 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved