Re: [VB6 ] 請教強制取消Shell所執行的程式

看板Visual_Basic作者 (YFU)時間18年前 (2007/01/18 21:08), 編輯推噓2(201)
留言3則, 1人參與, 最新討論串2/3 (看更多)
剛剛在網路上看到另一個作法 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
有想過 EnumWindow 尋找該 pid 擁有的視窗
01/19 07:10, 1F

01/19 07:11, , 2F
SendMessage 要求關閉視窗
01/19 07:11, 2F

01/19 07:13, , 3F
但沒試過行不行得通
01/19 07:13, 3F
文章代碼(AID): #15ht4mYb (Visual_Basic)
文章代碼(AID): #15ht4mYb (Visual_Basic)