程序代码如下,单击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
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
你设置断点看看hprogram = OpenProcess(0, False, a)这句执行完以后hprogram取到值没有,如果是0的话试试提升你的程序的权限,或者换用别的方法。
hprogram = OpenProcess(1&, False, a)
TerminateProcess hprogram, 0
If Not hprogram = 0 Then
MsgBox "runing"
Else
MsgBox "close"
End If
CloseHandle (a)
End Sub 这样试试