感谢Mike Drucker,我做到了:
(ProcessName = 没有“.exe”的执行文件名 - “skype.exe” ===> “skype”)
Private Sub StartProcessAndNormalize(Path As String, ProcessName As String, Optional Args As String = "", Optional PrintLog As Boolean = False)
If PrintLog = True Then Console.WriteLine("Starting --->" + ProcessName)
StartCmdProcess(Path, Args, ProcessName)
ProcessBackToNormal(ProcessName)
End Sub
Private Sub ProcessBackToNormal(ProcessName As String)
Dim proc As Process
Threading.Thread.Sleep(2000)
proc = (From p In System.Diagnostics.Process.GetProcessesByName(ProcessName) Order By p.StartTime Descending).FirstOrDefault()
Try
proc.PriorityClass = ProcessPriorityClass.Normal
Catch
Console.WriteLine("Can't find process " & ProcessName)
End Try
End Sub
Private Sub StartCmdProcess(Path As String, Args As String, Optional ProcessName As String = "")
Dim proc As Process = New Process
proc.StartInfo.FileName = "cmd.exe"
proc.StartInfo.Arguments = "/c start """ & ProcessName & """ /BelowNormal """ & Path & """ " & Args
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
proc.Start()
proc.WaitForExit()
End Sub
我们像这样使用它:
StartProcessAndNormalize("C:\Program Files (x86)\Skype\Phone\Skype.exe", "Skype", "/nosplash /minimized", showLog)