用vb代开关闭exe文件

前端之家收集整理的这篇文章主要介绍了用vb代开关闭exe文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  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("F:\webServer\mongoose-3.7.exe",vbNormalFocus)
    If pid = 0 Then
        MsgBox "没有打开程序"
    Else
        hProcess = OpenProcess(PROCESS_TERMINATE,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
原文链接:https://www.f2er.com/vb/259127.html

猜你在找的VB相关文章