看板 Visual_Basic 關於我們 聯絡資訊
剛剛在網路上看到另一個作法 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
fumizuki:有想過 EnumWindow 尋找該 pid 擁有的視窗 01/19 07:10
fumizuki:SendMessage 要求關閉視窗 01/19 07:11
fumizuki:但沒試過行不行得通 01/19 07:13