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

简介:

很多的情况下,需要以指定的账户运行程序;

例如在非管理员账户下要以管理员权限运行程序,就可以用下面的PS脚本:

1
2
3
4
5
6
7
8
<#
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




本文转自 bannerpei 51CTO博客,原文链接:http://blog.51cto.com/281816327/1553680,如需转载请自行联系原作者

相关文章
|
6天前
|
存储 JSON 运维
【运维】Powershell 服务器系统管理信息总结(进程、线程、磁盘、内存、网络、CPU、持续运行时间、系统账户、日志事件)
【运维】Powershell 服务器系统管理信息总结(进程、线程、磁盘、内存、网络、CPU、持续运行时间、系统账户、日志事件)
57 0
|
6天前
|
运维 开发工具 Windows
PowerShell系列(五):PowerShell通过脚本方式运行笔记
【1月更文挑战第7天】方便迁移,比如在之前工作经验积累下来的运维脚本,可以保存下来。如果业务场景用的到的话,直接文件拷贝过来就可以运行。
|
6天前
|
前端开发 微服务 Windows
PowerShell 命令窗口执行 pnpm 命令报错 无法加载文件 pnpm.ps1,因为在此系统上禁止运行脚本
PowerShell 命令窗口执行 pnpm 命令报错 无法加载文件 pnpm.ps1,因为在此系统上禁止运行脚本
|
Windows
powershell配置anaconda及解决【无法加载文件C:\Users\xxx\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本】的问题
powershell配置anaconda及解决【无法加载文件C:\Users\xxx\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本】的问题
1690 0
|
资源调度
关于vscode,powershell运行yarn报错禁止运行脚本解决办法
关于vscode,powershell运行yarn报错禁止运行脚本解决办法
157 0
关于vscode,powershell运行yarn报错禁止运行脚本解决办法
|
资源调度
PowerShell yarn : 无法加载文件 C:\Users\Admin\AppData\Roaming\npm\yarn.ps1,因为在此系统因为在此系统上禁止运行脚本。
PowerShell yarn : 无法加载文件 C:\Users\Admin\AppData\Roaming\npm\yarn.ps1,因为在此系统因为在此系统上禁止运行脚本。
183 0
PowerShell yarn : 无法加载文件 C:\Users\Admin\AppData\Roaming\npm\yarn.ps1,因为在此系统因为在此系统上禁止运行脚本。
|
jenkins 持续交付 Windows
Jenkins基础--Windows批处理,PowerShell获取指定的Credentials账户信息
Jenkins中Windows批处理,PowerShell获取指定的Credentials账户信息
4827 0