1

I am already 80% finished with my program but this is really what I need to know how.

I want to add progress bar in it so the user will know of it was installed fine.

Here's my code

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();
}
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • Why not use the standard setup project, which includes progress meters etc.? http://stackoverflow.com/questions/6090913/make-an-installation-program-for-c-sharp-applications-and-include-net-framework – Matt Evans Aug 18 '16 at 10:53
  • @MatthewEvans [Add-AppxPackage](https://technet.microsoft.com/en-us/library/hh856048.aspx) *is* the installer. It is a powershell command that installs app packages. The OP is asking how to capture and display the command's progress – Panagiotis Kanavos Aug 18 '16 at 10:57
  • You can use Powershell directly to run a script and get access to output streams like Verbose, Error and Progress as shown [in this question](http://stackoverflow.com/questions/34398023/get-powershell-commands-output-when-invoked-through-code), eg `psinstance.Streams.Progress.DataAdded += myProgressEventHandler;`. The event handler will receive strongly typed `ProgressRecord` objects – Panagiotis Kanavos Aug 18 '16 at 11:02
  • Ok... Thanks for the answers. – Carlos Miguel Salamat Aug 20 '16 at 11:57

0 Answers0