Re: [VB6 ] 請教強制取消Shell所執行的程式
剛剛在網路上看到另一個作法
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function IsWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Const PROCESS_QUERY_INFORMATION = &H400
Const SYNCHRONIZE = &H100000
Const STILL_ALIVE = &H103
Const INFINITE = &HFFFF
Private ExitCode As Long
Private hProcess As Long
Private isDone As Long
Private Sub CommandButton1_Click()
Dim pid As Long
Dim ExitEvent As Long
pid = Shell("notepad.exe", vbMinimizedFocus)
hProcess = OpenProcess(0, 0, pid)
ExitEvent = WaitForSingleObject(hProcess, 1500)
Call CloseHandle(hProcess)
Open "c:\killcmd.bat" For Output As #1
Print #1, "ntsd -c q -p " & pid
Close #1
Shell "c:\killcmd.bat", vbMinimizedFocus '最小化?行?束?程命令
MsgBox ("Finish")
End Sub
可以把筆記本關掉,但如果執行內容為ping 168.95.1.1 -t也是cmd視窗這招好像就不行了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.217.165.152
推
01/19 07:10, , 1F
01/19 07:10, 1F
推
01/19 07:11, , 2F
01/19 07:11, 2F
→
01/19 07:13, , 3F
01/19 07:13, 3F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 3 篇):
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章