程序代码如下,单击command1可以运行CityOnMap_Raise.exe可是为什么我单击command2结束不了它呢?希望高手指点一下,谢谢!!!
 Public Declare Function OpenProcess Lib "kernel32" (ByVal dwdesiredaccess As Long, _
 ByVal hinherithandle As Long, ByVal dwprocessecid As Long) As Long
 Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess _
     As Long, ByVal uExitCode As Long) As Long
  Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
 
 
Dim a As Long
Dim hprogram As Long
Private Sub Command1_Click()
a = Shell("C:\Program Files\城际高科\Raise\CityOnMap_Raise.exe", vbNormalFocus)End SubPrivate Sub Command2_Click()
hprogram = OpenProcess(0, False, a)
TerminateProcess hprogram, 0
If Not hprogram = 0 Then
 MsgBox "runing"
 Else
  MsgBox "close"
 End If
CloseHandle (a)
End Sub

解决方案 »

  1.   

    权限不够?还是目标exe把openprocess给HOOK了?
    你设置断点看看hprogram = OpenProcess(0, False, a)这句执行完以后hprogram取到值没有,如果是0的话试试提升你的程序的权限,或者换用别的方法。
      

  2.   

    如果openprocess能成功,那可能是你的程序权限不够,或者对方exe把TerminateProcess给HOOK了。
      

  3.   

    Private Sub Command2_Click() 
    hprogram = OpenProcess(1&, False, a) 
    TerminateProcess hprogram, 0 
    If Not hprogram = 0 Then 
    MsgBox "runing" 
    Else 
      MsgBox "close" 
    End If 
    CloseHandle (a) 
    End Sub 这样试试
      

  4.   

    如果只是为了关闭进程,那么将OpenProcess的第一个参数置为1&也就是PROCESS_TERMINATE就行了。