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

效果图

窗体里放一个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
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
################

天津网站建设 http://www./
2004-05-20 18:10
快速回复:一个简单的进程管理程序
数据加载中...
 
   



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

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