如何在C#中输出shell执行进度并在进度条中显示?

时间:2016-08-16 09:27:48

标签: c# powershell

我已经80%完成了我的计划,但这确实是我需要知道的。

我想在其中添加进度条,以便用户知道它安装得很好。

这是我的代码

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog file = new OpenFileDialog();
    file.Title = "Choose Package File";
    file.InitialDirectory = @"c:\";
    file.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
    file.FilterIndex = 2;
    file.RestoreDirectory = true;
    if (file.ShowDialog() == DialogResult.OK)
    {
        textBox1.Text = file.FileName;
        this.appFile = file.FileName;
    }
}

private void button2_Click(object sender, EventArgs e)
{
    // It doesn't
    string command = "C:/Windows/System32/WindowsPowerShell/v1.0/Powershell.exe";
    string cmd = "add-appxpackage ";
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = command;
    startInfo.Arguments = cmd + appFile;
    process.StartInfo = startInfo;
    process.Start();
}

0 个答案:

没有答案