Click here to Skip to main content
15,789,698 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried executing the instruction
RunDll32.exe InetCpl.cpl,ResetIEtoDefaults
in command prompt and it works fine.
But my requirement is to run the same from a console application in c#.

What I have tried:

I have tried implementing my requirements using console application in C# in Visual Studio.
C#
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new     System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "RunDll32.exe";
startInfo.Arguments = "InetCpl.cpl,ResetIEtoDefaults";
process.StartInfo = startInfo;
process.Start();

The above piece of code didn't work. I tried in another way i.e.
C#
string cmdInst = "RunDll32.exe InetCpl.cpl,ResetIEtoDefaults";
System.Diagnostics.Process.Start("cmd.exe", cmdInst);

But this ended up with opening command prompt traversed to the present working directory.
Looking forward for the answers.
Posted
Updated 2-Aug-23 3:33am

Try setting the full path in the FileName property, perhaps.
 
Share this answer
 
Try this :

C#
Process cmd = new Process();
            cmd.StartInfo.FileName = "cmd.exe";
            cmd.StartInfo.RedirectStandardInput = true;
            cmd.StartInfo.RedirectStandardOutput = true;
            cmd.StartInfo.CreateNoWindow = true;
            cmd.StartInfo.UseShellExecute = false;
            cmd.Start();

            cmd.StandardInput.WriteLine("RunDll32.exe InetCpl.cpl,ResetIEtoDefaults");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900