I'm trying to run Command Prompt commands from C# code.
After Process.Start()
step is executed, console window shows
System error 1223 has occured. The operation was cancelled by the user.
Error:
But, as you can see, I'm not cancelling the operation.
My Code:
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = $"/C NET USE {driveChar}: {URL}";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.Start(); // After this step, console window shows the above error
StreamWriter streamWriter = process.StandardInput;
streamWriter.WriteLine(username);
...
...
// remaining code
What is going wrong? Any ideas on resolving this error?
EDIT:
I don't actually need to redirect standard output, so I modified my code to only redirect standard input. But I'm still getting the same error.