BOOL TerminateProcess( HANDLE hProcess, // handle to the process UINT uExitCode // exit code for the process );
BOOL TerminateProcess( HANDLE hProcess, // handle to the process UINT uExitCode // exit code for the process );=Boolean TerminateProcess(long hProcess, long uExitCode)
错了,应该是 TerminateProcess(long hProcess, long uExitCode) as Boolean最近VC用多了,不好意思
TerminateProcess(long hProcess, long uExitCode) as Boolean ???的确是 VC 用多了, :)TerminateProcess(byval hProcess as long, byval uExitCode as long) as long
通过一个Exe文件,Shell出了另一个无界面的frm11.exe文件以后,如何针对的关闭这个frm11.exe 之前做了实验test1.exe,其中的主要代码如下: Pid = Shell("c:\frm11.exe", 1) mWnd = InstanceToWnd(Pid) ExitProcess GetExitCodeProcess(mWnd, 0) 但关闭的不是frm11.exe,而是关闭了test1.exe正确的应该是不关闭test1.exe,关闭frm11.exe 回答:改成这样 Dim tmpID As Long mWnd = Shell("c:\frm11.exe", 1)GetWindowThreadProcessId (mWnd , tmpID) ExitProcess GetExitCodeProcess(tmpID, 0) VB调用Shell函数时返回值实际是ProcessID,使用OpenProcess可以得到Process的Handle。利用TerminateProcess就可以关闭程序。如下面的例子: Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess _ As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess _ As Long, ByVal uExitCode As Long) As Long Dim x Private Sub Command1_Click() x = Shell("NotePad.EXE", 1) End Sub Private Sub Command2_Click() hProgram = OpenProcess(0, False, x) TerminateProcess hProgram, 0 End Sub 这是我收藏的帖子,适合你
HANDLE hProcess, // handle to the process
UINT uExitCode // exit code for the process
);
HANDLE hProcess, // handle to the process
UINT uExitCode // exit code for the process
);=Boolean TerminateProcess(long hProcess, long uExitCode)
TerminateProcess(long hProcess, long uExitCode) as Boolean最近VC用多了,不好意思
之前做了实验test1.exe,其中的主要代码如下:
Pid = Shell("c:\frm11.exe", 1)
mWnd = InstanceToWnd(Pid)
ExitProcess GetExitCodeProcess(mWnd, 0)
但关闭的不是frm11.exe,而是关闭了test1.exe正确的应该是不关闭test1.exe,关闭frm11.exe
回答:改成这样
Dim tmpID As Long
mWnd = Shell("c:\frm11.exe", 1)GetWindowThreadProcessId (mWnd , tmpID)
ExitProcess GetExitCodeProcess(tmpID, 0)
VB调用Shell函数时返回值实际是ProcessID,使用OpenProcess可以得到Process的Handle。利用TerminateProcess就可以关闭程序。如下面的例子:
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess _
As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess _
As Long, ByVal uExitCode As Long) As Long
Dim x Private Sub Command1_Click()
x = Shell("NotePad.EXE", 1)
End Sub Private Sub Command2_Click()
hProgram = OpenProcess(0, False, x)
TerminateProcess hProgram, 0
End Sub
这是我收藏的帖子,适合你