[C#] 纯文本查看 复制代码
var processInfo = new System.Diagnostics.ProcessStartInfo
{
Verb = "runas /trustlevel:0x20000",
LoadUserProfile = true,
FileName = "powershell.exe",
//Arguments = "Get-Process", //成功
Arguments = "Start-VM -name \"win11-Lite\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
var p = System.Diagnostics.Process.Start(processInfo);
while (!p.StandardOutput.EndOfStream)
{
string line = p.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(line))
{
rtb.Document.Blocks.Add(new Paragraph(new Run(line)));
}
}
[C#] 纯文本查看 复制代码
var processInfo = new System.Diagnostics.ProcessStartInfo
{
Verb = "runas",
LoadUserProfile = true,
FileName = "powershell.exe",
Arguments = "Start-sleep -seconds 10",
RedirectStandardOutput = false,
UseShellExecute = true,
CreateNoWindow = true
};
var p = System.Diagnostics.Process.Start(processInfo);
[C#] 纯文本查看 复制代码
var cmd = "mshta.exe vbscript:CreateObject(\"Shell.Application\").ShellExecute(\"powershell.exe\",\"Start-VM -name 'win11-Lite'\",\"\",\"runas\",1)(window.close)";
process.Start();
process.StandardInput.WriteLine(cmd);
process.StandardInput.AutoFlush = true;
process.StandardInput.WriteLine("exit");