using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var newProcessInfo = new System.Diagnostics.ProcessStartInfo();
newProcessInfo.FileName = @"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe";
newProcessInfo.Verb = "runas";
System.Diagnostics.Process.Start(newProcessInfo);
newProcessInfo.Arguments = @"sfc /scannow";
}
}
}
所以我的代码可以运行到一定程度。点击Windows窗体应用程序按钮后,它将以管理员身份在64位的Windows Powershell中运行,但是不会运行一个.ps1脚本“c:\path\script.ps1”或者像上面那样直接写出的命令“sfc /scannow”。
我读到过如果代码开头没有加载"Set-ExecutionPolicy Unrestricted",有时PowerShell命令无法正常工作。
请帮忙!我已经到处寻找答案了。
[...]\SysWOW64\[...]\powershell.exe
是 32 位 PowerShell。 - Mathias R. JessenC:\Windows\System32\*
的文件时,文件系统重定向器会检查SysWOW64中是否存在相应的32位映像并重定向调用。因此,在64位Windows上:System32 = 64位映像,SysWOW64 = 32位映像。 - Mathias R. Jessen