0

I got error win32exception was unhandled using this in class on this part

Process dip = new Process();
dip.StartInfo.FileName = @"C:\Windows\System32\diskpart.exe";
dip.StartInfo.RedirectStandardInput = true;
dip.StartInfo.RedirectStandardOutput = true;
dip.StartInfo.CreateNoWindow = true;
dip.StartInfo.UseShellExecute = false;
dip.Start();
dip.StandardInput.WriteLine("list disk");
dip.StandardInput.Flush();
dip.StandardInput.Close();
dip.WaitForExit();

on dip.Start(); program paused and i saw that error. how can i fix this? please help!

Mohamad
  • 19
  • 4
  • 1
    If your intention is to mimic the command `C:\Windows\System32\diskpart.exe list disk` you should put the `list disk` into an [Argument](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.arguments?view=netcore-3.1) instead of trying to use StandardInput. – Filburt Jun 23 '20 at 15:56
  • even if i make list disk command it doesn't start the diskpart.exe – Mohamad Jun 23 '20 at 16:21
  • 1
    what exactly is message with the win32exception ? diskpart requires administrative access... are you running your program as admin? – Jawad Jun 23 '20 at 16:26
  • yes my program runs as admin – Mohamad Jun 23 '20 at 16:51
  • Just out of curiosity: What is your ultimate goal? I suspect a [XY problem](https://en.wikipedia.org/wiki/XY_problem) here. – Filburt Jun 24 '20 at 06:40

0 Answers0