您的位置:首页 > 运维架构 > Shell

【Powershell】以指定的账户运行程序

2014-09-17 11:49 387 查看
很多的情况下,需要以指定的账户运行程序;
例如在非管理员账户下要以管理员权限运行程序,就可以用下面的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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐