CMD – 執行 .bat 檔之後 如何關閉CMD視窗
CMD – 執行 .bat 檔之後 如何關閉CMD視窗
資料來源: https://www.weithenn.org/2014/01/cmd-exit-after-exec-batch-file.html
code(bat)
@ECHO OFF REM 執行對應軟體 CMD不咬住(不等待對應程式執行完畢,才繼續往後執行) start "" "C:\Program Files (x86)\WinEdt Team\WinEdt\WinEdt.exe" REM 關閉CMD畫面 exit
code(C#)
public static void ShowSoftKeyboard()//顯示/呼叫 螢幕鍵盤/軟體鍵盤 { try { //關閉螢幕鍵盤(尋找已開啟的軟體並將它關閉) System.Diagnostics.Process[] MyProcess = System.Diagnostics.Process.GetProcessesByName("osk"); if (MyProcess.Length > 0) { MyProcess[0].Kill(); } //Any CPU 寫法 //https://social.msdn.microsoft.com/Forums/vstudio/en-US/3cf45aac-fab9-45f0-b416-cc504daf71da/processstart-elevation-and-uac?forum=csharpgeneral /*Process process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.WorkingDirectory = "C:\\"; process.StartInfo.FileName = "C:\\WINDOWS\\system32\\osk.exe"; //process.StartInfo.Verb = "runas"; process.Start();*/ //透過cmd的start執行軟體鍵盤 讓cmd不咬住 並且透過exit將cmd畫面關閉 [透過cmd克服C# x32程式無法呼叫 x64系統應用程式的問題] Process.Start(@"c:\Windows\Sysnative\cmd.exe", "/c start osk.exe exit"); } catch (Exception ex) { String StrLog = String.Format("{0}:{1}", "ShowSoftKeyboard", ex.ToString()); LogFile.Write("ProcessError ; " + StrLog); } }
PS. JAVA UI應用程式也會應用類似技巧來做為啟動程式的技巧 (EX: apache-jmeter)