Click here to Skip to main content
15,899,937 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to open an exe file from C# Code. But that exe does not open directly , it open from cmd and require an argument before running. I've found many piece of codes but everyone is talking about to open CMD from C#. I'm confuse how to run a command inside CMD from C# Code , which also require and command as well?

What I have tried:

This is I've been trying yet.
C#
 ProcessStartInfo startInfo = new ProcessStartInfo();

 //startInfo.WindowStyle = ProcessWindowStyle.Hidden;

 startInfo.WorkingDirectory = "C:\\Program Files (x86)\\Maxim Integrated Products\\MPC\\MAX32550";
// In this directory there is an "abc.exe" file that I want to open and that exe cannot be start without providing an argument "abc.ini" .
 startInfo.FileName = "cmd.exe";

 MpcProc.StartInfo = startInfo;

 MpcProc.Start();
Posted
Updated 26-Mar-18 1:26am
v2

Forget cmd, that's just a console app to let people run commands. Start the process directly and pass the required arguments to it

Process.Start Method (String, String) (System.Diagnostics)[^]
 
Share this answer
 
Comments
Ammar Shaukat 26-Mar-18 7:15am    
It worked but Still there is a configuration error. I'm not sure but there might be some problem with provided argument.

Process.Start(@"C:\Program Files (x86)\Maxim Integrated Products\MPC\MAX32550\mpc.exe", "mpc.ini");
You need to set the Working directory, or it remains the same as the "Parent" process:
ProcessStartInfo psi = new ProcessStartInfo(pathToExe, arguments);
psi.WorkingDirectory = Path.GetDirectoryName(pathToExe);
Process.Start(psi);
 
Share this answer
 
Comments
Ammar Shaukat 26-Mar-18 7:35am    
This is working , Thanks.
OriginalGriff 26-Mar-18 7:38am    
You're welcome!

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