10
2012
06

vb关闭应用程序

最简单的 shell "cmd.exe /c taskkill /im 进程名称 /f" 其次 sendmessage WM_QUIT。。。 再次 OpenProcess, TerminateProcess 在vb6等待外部应用程序执行完成 Option Explicit 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 WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Const SYNCHRONIZE = &H100000 Private Const INFINITE = &HFFFFFFFF Private Sub Command1_Click() 'Dim pId&, pHnd& '声明pId 变量存储Process Id '声明pHnd 变量存储Process Handle 'pId = Shell("Notepad", vbNormalFocus) 'Shell传回Process Id 'pHnd = OpenProcess(SYNCHRONIZE, 0, pId) '取得 Process Handle Dim pHnd& '进程句柄 pHandle 'Dim pId& 'pid = shell("notepad", vbnormalfocus) pHnd = OpenProcess(SYNCHRONIZE, 0, Shell("Notepad", vbNormalFocus)) If pHnd <> 0 Then Call WaitForSingleObject(pHnd, INFINITE) '无限等待,直到程序结束 Call CloseHandle(pHnd) MsgBox ("记事本已经关闭!") End If End Sub
« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。