end行不行?我也是初学!嗬嗬!
解决方案 »
- 各位大虾,小弟有一个关于VBA的问题,对我来说是超级难,请多多帮助
- 有一些换肤软件可以对一些软件的皮肤进行更改,请问它的原理是什么呢?
- WebBrows 控件 调用 一个HTML页面,如果屏蔽 HTML 里的 onunload=window.open
- SetWindowLong设置在任务栏不可见
- 请帮助弱智儿童呀,谢谢了!!!!!!!!!!
- vb如何调用一个用 c#写的.dll文件里的某个函数。
- 怎样才能获得系统的CPU的ID号、网卡MAC之类的系统信息(要代码)(100分)
- 装完real后工程库中的real控件只能放声音不能视频
- 史无前例简单的问题:如何为ADO DATA控件建立(*.udl)数据源:
- VB中关于DLL的升级问题?
- 初学者的问题:Windows计算器效果的实现
- 请wgf001(我心永恒)来拿分
在你的程序中用shell语句可以执行外部程序!
要结束的话先用
API函数:FindWindow(类,程序的窗口的名子)如果成功函数返回那个程序的
句柄,否则为0 , 其中类和名子知道其中之一就可以了
然后用PostMessage(句柄,&H10,0,0)就可以关闭了!
如:
Private Sub Command1_Click()
Dim a As Long
a = FindWindow(vbNullString, "Test - 记事本")
If a <> 0 Then
PostMessage a, &H10, 0, 0
End If
End Sub
Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
说明
结束一个进程
在VB里使用
可以使用,但尽量不用
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hProcess Long,指定要中断的一个进程的句柄
uExitCode Long,进程的一个退出代码
用aip函数:findwindow找到要中止程序的窗口句柄后再用PostMessage(句柄,&H10,0,0)来kill它哈…!
Form1.frm:Dim i As Integer
Dim NumofProcess As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongPrivate Const WM_NULL = &H0
Private Const SMTO_BLOCK = &H1
Private Const SMTO_ABORTIFHUNG = &H2
Dim objActiveProcess As Class1Private Sub Command1_Click()
Call Jiluheike(1)End SubPrivate Sub Command2_Click()
Call Jiluheike(0)End SubPrivate Sub Command3_Click()
Dim lpID As Long
Dim lProcess As Long
Dim lReturn As Long
lpID = ls2.ItemData(ls2.ListIndex)
If MsgBox("really stop it", vbOKCancel + vbExclamation) = vbCancel Then Exit Sub
lProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, lpID)
lReturn = TerminateProcess(lProcess, 0&)
ls2.RemoveItem ls2.ListIndex
ls2.Selected(0) = True
End SubPrivate Sub Command4_Click()
End
End SubPrivate Sub Form_Unload(Cancel As Integer)
Set objActiveProcess = NothingEnd SubSub Jiluheike(isjilu As Integer)
Set objActiveProcess = New Class1
NumofProcess = objActiveProcess.GetActiveProcess
Select Case isjilu
Case 0
ls2.Clear
For i = 0 To NumofProcess
ls2.AddItem objActiveProcess.szExeFile(i)
ls2.ItemData(i) = objActiveProcess.th32ProcessID(i)
Next
Command3.Enabled = True
Case 1
ls1.Clear
For i = 0 To NumofProcess
ls1.AddItem objActiveProcess.szExeFile(i)
ls1.ItemData(i) = objActiveProcess.th32ProcessID(i)
Next
ls1.RemoveItem 0
'ls2.Selected(0) = True
End Select
End Subprocess.cls:Option ExplicitPrivate Const TH32CS_SNAPPROCESS As Long = 2&
Private Const MAX_PATH As Integer = 260
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
dwFlages As Long
szExeFile As String * MAX_PATH
End TypePrivate 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 Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
'关闭一个内核对象
Dim ListOfActiveProcess() As PROCESSENTRY32Public Function GetActiveProcess() As Long
Dim hToolhelpSnapshot As Long
Dim tProcess As PROCESSENTRY32
Dim r As Long, i As Integer
hToolhelpSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
With tProcess
.dwSize = Len(tProcess)
r = ProcessFirst(hToolhelpSnapshot, tProcess)
ReDim Preserve ListOfActiveProcess(20)
Do While r
i = i + 1
If i Mod 20 = 0 Then ReDim Preserve ListOfActiveProcess(i + 20)
ListOfActiveProcess(i) = tProcess
r = ProcessNext(hToolhelpSnapshot, tProcess)
Loop
End With
GetActiveProcess = i
Call CloseHandle(hToolhelpSnapshot)End FunctionPublic Function szExeFile(ByVal Index As Long) As String '进程文件名称,路径
szExeFile = ListOfActiveProcess(Index).szExeFileEnd FunctionPublic Function th32ProcessID(ByVal Index As Long) As Long '进程标示代码
th32ProcessID = ListOfActiveProcess(Index).th32ProcessIDEnd Function