简体   繁体   English

使用管理员凭据启动进程并使用 RunAs 执行程序文件 C 中的特定 exe

[英]Start Process With Admin Credential and use RunAs to Execute specific exe in Program File C

I have this Code working perfectly and open CMD but it cannot run specific exe like chrome.我有这个代码完美运行并打开 CMD 但它不能像 chrome 一样运行特定的 exe。

$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);

In ps1File I have this code在 ps1File 我有这段代码

Start-Process -FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -Verb RunAs启动进程 -FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -Verb RunAs

Working perfectly...工作完美...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM