很多的情况下,需要以指定的账户运行程序;
例如在非管理员账户下要以管理员权限运行程序,就可以用下面的PS脚本:
<# Script Editor: Snail Yu Date: 2014-09-17 #> $uname=".\administrator" #指定用户名,“.\administrator”代表本地管理员 $pwd=ConvertTo-SecureString "password" -AsPlainText –Force #“password”指本地管理员的密码 $cred=New-Object System.Management.Automation.PSCredential($uname,$pwd) #将用户和密码保存在这个变量中 Start-Process -FilePath "C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe" -Credential $cred #以指定的账户运行QQ
参考网址:
http://biancheng.dnbcw.info/mssql/374833.html
http://www.pstips.net/powershell-launching-applications-with-alternate-credentials.html