答案1
以管理员身份打开终端(wt.exe):
- 任务栏
固定wt.exe
到Taskbar
,然后Shift + Right Click
> 以管理员身份运行
- 脚本
# openwtadmin.ps1
# select profil betwen
$prof = 'PowerShell'
#$prof = 'Windows PowerShell'
Start -Verb RunAs -FilePath "wt.exe" -argumentlist "-p `"$prof`""
如果您想通过终端运行提升的脚本,请在脚本顶部添加下面的脚本。
它将自动:
- 获得管理员提升
- 在终端中运行(如果已安装)
- 最好使用 pwsh.exe(如果安装了 powershel 7xx)
# set default console to WT.exe (if installed)
# set default commandline to PWSH.exe (if installed)
# Replace $True with $False to disable
$RuninWT = $True
$PreferPS7 = $True
$IsWT = where.exe wt.exe 2>$null
$HVM = (Host).Version.Major
if ( $HVM -eq 7 -and $PreferPS7 ) {
$p = 'pwsh.exe'; $prof = 'PowerShell'
} else {
$p = 'powershell.exe'; $prof = 'Windows PowerShell'
}
if ( (fltmc).Count -eq 3 ) {
if ( $IsWT -and $RuninWT ) {
$arg1 = "-d `"$PSScriptRoot`" -p `"$prof`"", "cmd /c $p -NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
Start -Verb RunAs -FilePath "wt.exe" -ArgumentList $arg1;
taskkill.exe /f /im $PID; exit 0
} else {
$arg2 = "-NoProfile", "-ExecutionPolicy Bypass", "-File `"$PSCommandPath`""
Start -Verb RunAs -FilePath $p -ArgumentList $arg2; exit 0
}
}
'Your Script Here'
pause