vb关闭应用程序

2012-06-10 20:36:07  阅读 4844 次 评论 0 条

最简单的 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

本文地址:http://financialos.cn/?id=52
免责声明:本文为原创文章,版权归 jinesc 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?