很多的情況下,需要以指定的賬戶運作程式;
例如在非管理者賬戶下要以管理者權限運作程式,就可以用下面的PS腳本:
1
2
3
4
5
6
7
8
<code><#</code>
<code>Script Editor: Snail Yu</code>
<code>Date: 2014-09-17</code>
<code>#></code>
<code>$uname</code><code>=</code><code>".\administrator"</code> <code>#指定使用者名,“.\administrator”代表本地管理者 </code>
<code>$pwd</code><code>=</code><code>ConvertTo-SecureString</code> <code>"password"</code> <code>-AsPlainText –Force </code><code>#“password”指本地管理者的密碼 </code>
<code>$cred</code><code>=</code><code>New-Object</code> <code>System.Management.Automation.PSCredential(</code><code>$uname</code><code>,</code><code>$pwd</code><code>) </code><code>#将使用者和密碼儲存在這個變量中 </code>
<code>Start-Process</code> <code>-FilePath </code><code>"C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe"</code> <code>-Credential </code><code>$cred</code> <code>#以指定的賬戶運作QQ</code>
參考網址:
<a href="http://biancheng.dnbcw.info/mssql/374833.html" target="_blank">http://biancheng.dnbcw.info/mssql/374833.html</a>
<a href="http://www.pstips.net/powershell-launching-applications-with-alternate-credentials.html" target="_blank">http://www.pstips.net/powershell-launching-applications-with-alternate-credentials.html</a>
本文轉自 bannerpei 51CTO部落格,原文連結:http://blog.51cto.com/281816327/1553680,如需轉載請自行聯系原作者