【发布时间】:2015-09-08 06:58:22
【问题描述】:
我有一个 PowerShell 脚本 Admin.PS1,它将以管理员身份打开运行 other.PS1 PowerShell 脚本。代码如下:
$ScriptPath = "D:\usefull_PS_files\toNode\other.PS1"
$RelaunchArgs = '-ExecutionPolicy Unrestricted -file "' + $ScriptPath + '" -IsRunAsAdmin'
# Launch the process and wait for it to finish
try
{
$AdminProcess = Start-Process "$PsHome\PowerShell.exe" -Verb RunAs -ArgumentList $RelaunchArgs
}
catch
{
$Error[0] # Dump details about the last error
exit 1
}
现在发生的情况是,当我执行上面的 PS 脚本时,我得到一个 PowerShell 管理员提示,我必须在其中选择“是”或“否”,但我真正想要的是 Other.PS1 以管理员身份执行而没有任何提示,即无需选择“是”或“否”。
那么,我怎样才能以完全自动化的方式以管理员身份运行任何 PS 脚本而无需我的输入。
【问题讨论】:
标签: powershell uac