Click here to Skip to main content
15,906,628 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I have an off-the-wall question. I would like to run an executable. Here is the code I have.

C#
public void RunProgram(string rawFile,string configFile)
         {
               proc.EnableRaisingEvents = false;
               proc.StartInfo = new ProcessStartInfo();
               proc.StartInfo.Arguments = "C:\\Users\\Iman\\Desktop\\ToxIDtest\\Exact_Mass_Test.raw";
               proc.StartInfo.WorkingDirectory = "C:\\Xcaliber\\system\\programs\\";
               proc.StartInfo.FileName = "ID.exe";
               proc.Start();
               proc.WaitForExit();
         }


The executable has some parameters in the gui though that I can change. How can I change or even find these parameters in the C# program that runs the executable. Is this an off-the-wall question? ID.exe is the executable program

Thanks for any input
Posted

1 solution

By the way, your code won't even compile, as proc is not defined. If this variable is declared outside your method, this would be really bad unsafe style. Also, you are using hard-coded file path names. There are no situations when hard-coded path names can be useful. The path names always should be calculated based on "special directories", executable directory or data (configuration) files.

When you say "in the GUI", it usually does not mean command line parameters which you really could supply as the string in your StartInfo. Other than that, there is no such concept as GUI parameters. There are controls which can change its status dynamically in response to the user input. The UI is not generally designed to be controlled in any other way. (There are exclusions though where "automation" can be used.) An attempt to controlling the UI application behavior is just wrong.

That said, even the whole idea of using System.Diagnostics.Process for "integration" should be used with care and best avoided. Real integration can be based on plug-ins, components, etc. With Process, you run a separate process; and the processes are well isolated from each other. There are different approaches such as based on simulation of user input and it can work, but the whole idea is one huge abuse. Programs should be developed, not "integrated". If you really have to do this for leaving, your life is miserable.

—SA
 
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