PowerShell 启动脚本
我错过了 DOSstart
命令,因此我将 @JuanPablo 的代码组合成一个名为的 shell 脚本PSstart.ps1
,您可以使用它来替换start
PowerShell 中的命令。
就像PowerShell -file PSStart.ps1 -affinity <affinity> -priority <priority> <path to executable> <executable arguments>
享受一样使用它!
param([Int32]$affinity=0xF,[String]$priority="NORMAL", [String]$appPath="", [String]$appArguments="")
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") # For message box error reports, remove if you don't want popup errors
$priorityValues = "LOW", "NORMAL", "HIGH", "REALTIME", "ABOVENORMAL", "BELOWNORMAL" # Remove ABOVENORMAL and BELOWNORMAL if running on Win98 or WinME
$priorityUC = $priority.ToUpper()
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
If($appPath -ne "" -and (Test-Path $appPath))
{
If($priorityValues -contains $priorityUC)
{
Try
{
$pinfo.FileName = $appPath
$pinfo.Arguments = $app_arguments
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start()
$p.PriorityClass=$priorityUC
$p.ProcessorAffinity=$affinity
}
Catch
{
$exceptionMessage = $_.Exception.Message
#Write-Host "An exception:`n`n$exceptionMessage`n`noccured!" -fore white -back red # Uncomment for console errors
[System.Windows.Forms.MessageBox]::Show("An exception:`n`n$exceptionMessage`n`noccured!", "An Exception Occured", "Ok", "Error");
Break
}
}
Else
{
#Write-Host "The priority: `"$priorityUC`" is not a valid priority value!" -fore white -back red # Uncomment for console errors
[System.Windows.Forms.MessageBox]::Show("The priority: `"$priorityUC`" is not a valid priority value!", "A Priority Error Occured", "Ok", "Error");
}
}
Else
{
#Write-Host "The application path: `"$appPath`" doesn't exist!", "A Path Error Occured" -fore white -back red # Uncomment for console errors
[System.Windows.Forms.MessageBox]::Show("The application path: `"$appPath`" doesn't exist!", "A Path Error Occured", "Ok", "Error");
}