last day (17 days later) » 

8:26 PM
1
A: How to launch an executable in C# with specific guidelines

jltremThe C++ code isn't using a command 'prompt', per se, but launching a process by providing a path the the executable to CreateProcess. You can accomplish the same thing in C# with the Process class. Configure Process.StartInfo and call the Start method. Regarding launching the executable with ...

 
So I can basically do all of that with the Process class? msdn.microsoft.com/en-us/library/vstudio/…
 
I think everything is configurable through StartInfo. Which params are you having a problem with? CREATE_NEW_CONSOLE is based off CreateNoWindow=false.
 
I'm actually just starting and wondering what to use in place of STARTUPINFO
This info is very helpful, but I am having trouble placing the file in the correct area and then locating it through my code. I will post my updated code in my question.
 
@Ericafterdark I updated my answer with exe path info
 
It looks like I still end up with the same error on the Process.Start(); line. I've verfied that the exe is in the location that I stated above
 
8:26 PM
@Ericafterdark "The system cannot find the file specified"? Then something is wrong with the path you are giving it. Log it or look at it in the debugger to verify the path.
 
Okay, it looks like it is tracing to bin->debug->(then looking for my "Executables" folder here). This is strange because "Executables" is on the same level as bin.
 
@Ericafterdark this q/a on SO is veering from the original question. For the purposes of answering your original question, hardcode the path and confirm that you can launch the exe.
 
Yeah, it worked. Thank you. Now I need to know how to make that path more dynamic so that it will work on other systems too.
Hey there
 
if you the exe that you want to launch will always be in a fixed location relative the running exe's path, then you can use AppDomain.CurrentDomain.BaseDirectory.
Otherwise you could go with making it configurable through the .config file
 
Can you show me an example of how to do this? Can I just put it in the debug folder with the program exe?
 
8:31 PM
if it is in the same directory as the exe (i.e., the 'debug' folder during development) then you can do this:
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MYEXECUTABLE.EXE");
ProcessStartInfo startInfo = new ProcessStartInfo(path);
Process.Start(startInfo);
the problem you ran into earlier was that MYEXECUTABLE.EXE wasn't in a subdir ... it was back one directory and then in a subdirectory of that.
 
That's perfect, then it should work on other computers besides my own. Thank you
 
you bet. good luck
 
Thanks, have a good one
 

  last day (17 days later) »