如题
解决方案 »
- 使用ScriptControl控件时,出现"System.NullReferenceException: 这个集合中找不到此项目"错误
- 组合键问题
- 如何在VB中调用存储过程啊,请手请教!!
- 如何取得DataGrid中处于选中状态的单元格的值
- 各位大侠,如何定义数组,可以在不同窗体间调用???急!!!!!!!!!!!!!!!!!!!!马上送分
- 为什么data控件绑定mdb文件时候再指定recordsource出错?
- 急: select 语法问题?
- 请教vb高手,dll如何加密?
- 大家一起来!拿起法律武器,绝对不能让 NESO 这只业界蟑螂继续进行欺诈!
- zilong:如何用VB+MSCOMM拨打传呼,有人会吗?(我是认真的,不是胡闹)
- 关于窗体左上解的系统菜单?
- tabstrip控件小问题,麻烦指点
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Private Sub CloseForm()'调用这个过程来关闭(在调试环境中会连VB都关掉的,小心保存代码)
Dim ProcessID As Long
ProcessID = GetCurrentProcessId()
ExitProcess (ProcessID)
End Sub
tztz520(午夜逛街)刚刚在另一个帖子里说的
Private ProcessID() As Long ' 按list1中的进程顺序存储所有进程ID'---------- API类型声明 -----------
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 * 1024
End TypePrivate Type MODULEENTRY32 '模块
dwsize As Long
th32ModuleID As Long
th32ProcessID As Long
GlblcntUsage As Long
ProccntUsage As Long
modBaseAddr As Byte
modBaseSize As Long
hModule As Long
szModule As String * 256
szExePath As String * 1024
End TypePrivate Type THREADENTRY32 '线程
dwsize As Long
cntusage As Long
th32threadID As Long
th32OwnerProcessID As Long
tpBasePri As Long
tpDeltaPri As Long
dwFlags As Long
End Type
'----------------------------------------- API声明 -------------------------------------------------------
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Module32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As MODULEENTRY32) As Long
Private Declare Function Module32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As MODULEENTRY32) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Thread32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As THREADENTRY32) As Long
Private Declare Function Thread32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As THREADENTRY32) As Long
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 GetCurrentProcessId Lib "kernel32" () As Long'---------------------------------------- API常数声明 ------------------------------------------------------
Private Const TH32CS_SNAPHEAPLIST = &H1
Private Const TH32CS_SNAPPROCESS = &H2
Private Const TH32CS_SNAPTHREAD = &H4
Private Const TH32CS_SNAPMODULE = &H8
Private Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Private Const TH32CS_INHERIT = &H80000000
Private Const PROCESS_TERMINATE = &H1&Private Sub Command1_Click()
Dim Process As PROCESSENTRY32
Dim ProcSnap As Long
Dim cntProcess As Long
cntProcess = 0
List1.Clear
ProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If ProcSnap Then
Process.dwsize = 1060 ' 通常用法
Process32First ProcSnap, Process
Do Until Process32Next(ProcSnap, Process) < 1 ' 遍历所有进程直到返回值为False
List1.AddItem Trim(Process.szExeFile)
cntProcess = cntProcess + 1
Loop
End If
ReDim ProcessID(cntProcess) As Long
Dim i As Long
i = 0
Process32First ProcSnap, Process
Do Until Process32Next(ProcSnap, Process) < 1 ' 遍历所有进程直到返回值为False
ProcessID(i) = Process.th32ProcessID
i = i + 1
Loop
CloseHandle (ProcSnap)
End SubPrivate Sub Command2_Click()
Dim c As Integer
If List1.ListIndex < 0 Then
MsgBox "请选择进程!", vbOKOnly + vbInformation, "提示"
Else
Dim hProcess As Long
hProcess = OpenProcess(PROCESS_TERMINATE, False, ProcessID(List1.ListIndex))
If hProcess Then TerminateProcess hProcess, 0
c = List1.ListCount
While List1.ListCount = c
Command1_Click
Wend
End If
End SubPrivate Sub Command3_Click()
Unload Me
End Sub
=========================================
行~?!!! 好象不行哦