powershell - 使用管理员凭据启动进程并使用 RunAs 执行程序文件 C 中的特定 exe
问题描述
我有这个代码完美运行并打开 CMD,但它不能运行特定的 exe,如 chrome。
$username = "username"
$password = "password"
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @("soft\abbas_104",(ConvertTo-SecureString -String "Abbas1122" -AsPlainText -Force))
Start-Process -PassThru -FilePath powershell -Credential $credentials -ArgumentList '-noprofile -command &{Start-Process ', cmd, ' -Wait -verb runas}'
解决方案
Testabc user have the administrator right.
//Run EXTERNAL APP AS AN ADMIN
var pass = new SecureString();
pass.AppendChar('t');
pass.AppendChar('e');
pass.AppendChar('s');
pass.AppendChar('t');
var ps1File = @"C:\Users\testabc\Desktop\LT_Admin.ps1";
ProcessStartInfo processAdmin;
processAdmin = new ProcessStartInfo();
processAdmin.UseShellExecute = false;
processAdmin.CreateNoWindow = true;
processAdmin.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
processAdmin.Password = pass;
processAdmin.UserName = "testabc";
processAdmin.Domain = "soft";
processAdmin.FileName = @"C:\windows\system32\windowspowershell\v1.0\powershell.exe";
processAdmin.Arguments = $"-NoProfile -ExecutionPolicy unrestricted -file \"{ps1File}\"";
processAdmin.RedirectStandardOutput = true;
Process.Start(processAdmin);
在 ps1File 我有这个代码
Start-Process -FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -Verb RunAs
完美运行...
推荐阅读
- http - 允许任何 CORS 来源 (*) 时是否应设置“Vary: Origin”?
- javascript - Fastify 模式验证不起作用。我是否以错误的方式配置了某些东西?
- asp.net - 如果列是主键的一部分,我可以删除它吗?
- javascript - Rock Paper Scissors 增加函数结果的标签值
- python - 2不同PC上的python套接字未连接
- wordpress - 无法验证 Apple 私人电子邮件中继服务的域
- python - Python - 导入 mysql - IDLE/works VisualStudio/dosn't work
- android - Android 10 双自拍相机回归?
- html - CSS - 滚动时让导航栏粘在固定顶部的导航栏上?
- backbone.js - 为什么我的backbone.js 集合没有加载正确的数据列表?