VB中关闭shell打开的外部EXE程序

您所在的位置:网站首页 vb退出应用程序的代码怎么写 VB中关闭shell打开的外部EXE程序

VB中关闭shell打开的外部EXE程序

2024-07-12 14:54| 来源: 网络整理| 查看: 265

Private   Declare   Function   TerminateProcess   Lib   "kernel32"   _      (ByVal   hProcess   As   Long,   ByVal   uExitCode   As   Long)   As   Long           Const   PROCESS_QUERY_INFORMATION   =   &H400      Private   hProcess   As   Long      -----------------在程序中------------------              Dim   pid   As   Long                           pid   =   Shell("notepad.exe",   vbNormalFocus)              hProcess   =   OpenProcess(PROCESS_QUERY_INFORMATION,   0,   pid)      ----------------如果要关闭-----------------      If   hProcess     0   Then      aa   =   TerminateProcess(hProcess,   3838)      End   If   

 ***********************************************************************************************************

ExitProcess  VB声明  Declare Sub ExitProcess Lib "kernel32" Alias "ExitProcess" (ByVal uExitCode As Long)  说明  中止一个进程  参数表  参数 类型及说明  uExitCode Long,指定想中断的那个进程的一个退出代码  在VB中使用  应尽量避免用该函数来关闭进程。不要在自己的VB程序中使用它。此时,应试着向要关闭的那个程序的主窗口投递一条WM_CLOSE消息  ***************************************************************************************************************  Option   Explicit           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   Const   PROCESS_TERMINATE   =   &H1      Private   hProcess   As   Long      '打开进程      Private   Sub   Command1_Click()              Dim   pid   As   Long              pid   =   Shell("c:/winnt/System32/calc.exe",   vbNormalFocus)              If   pid   =   0   Then                      MsgBox   "没有打开程序"              Else                      hProcess   =   OpenProcess(PROCESS_TERMINATE,   0,   pid)              End   If      End   Sub      '关闭进程      Private   Sub   Command2_Click()              Dim   l   As   Long              l   =   TerminateProcess(hProcess,   1)              If   l     0   Then                      MsgBox   "成功关闭"              Else                      MsgBox   "未关闭"              End   If      End   Sub   



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3