C # Launch an application with multiple arguments

I am trying to start an application from a C # application, but it does not start properly. From cmd, the application plus the arguments launches a small window showing the exit, and then the application is minimized to the system tray.

Launching an application from a C # application using the code below leads to a process appearing in the task manager, but nothing else, not an output window, an icon in the system tray. What could be the problem?

myProcess.StartInfo.FileName = ...; myProcess.StartInfo.Arguments = ...; myProcess.Start(); 

also tried to convey the following

  myProcess.StartInfo.RedirectStandardOutput = true; //tried both myProcess.StartInfo.UseShellExecute = false; //tried both myProcess.StartInfo.CreateNoWindow = false; 

using

  Process.Start(Filename, args) 

doesn't work either. Truly appreciate any help on how to handle this.

UPDATE: I think that the problem may be several arguments that should be passed to the process

 RunMode=Server;CompanyDataBase=dbname;UserName=user;PassWord=passwd;DbUserName=dbu;Server=localhost;LanguageCode=9 

considers

+7
c # process
source share
4 answers

I do not see an error in your code. I wrote a small program that outputs its arguments to the console

 static void Main (string[] args) { foreach (string s in args) Console.WriteLine(s); Console.Read(); // Just to see the output } 

and then I put it in C:, which is the name of the application "PrintingArgs.exe", so I wrote another one that runs the first:

 Process p = new Process(); p.StartInfo.FileName = "C:\\PrintingArgs.exe"; p.StartInfo.Arguments = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18"; p.Start(); 

this gives me the desired result of a list of numbers. The application that calls PrintingArgs exits when it reaches p.Start (), this can be avoided by using p.WaitForExit(); or just Console.Read(); . I also used both p.UseShellExecute and p.CreateNoWindow . Only if

 p.UseShellExecute = false; p.CreateNoWindow = true; 

makes the PrintingArgs application not show the window (even if I put only p.CreateNoWindow = true , it shows the window).

Now it comes to my mind that perhaps you are mistaken in passing arguments and forcing another program to fail and close immediately, or maybe you are not pointing to the desired file. Check the paths and names to find any error you might omit. Also using

  Process.Start(fileName, args); 

does not use the information configured with StartInfo in the Process instance.

Hope this helps, is considering

+7
source share

Not sure if anyone is still following this, but here is what I came up with.

 string genArgs = arg1 + " " + arg2; string pathToFile = "Your\Path"; Process runProg = new Process(); try { runProg.StartInfo.FileName = pathToFile; runProg.StartInfo.Arguments = genArgs; runProg.StartInfo.CreateNoWindow = true; runProg.Start(); } catch (Exception ex) { MessageBox.Show("Could not start program " + ex); } 

Adding a space to the line allowed me to pass two arguments to the program I wanted to run. The program ran without problems after the code execution.

+4
source share

Have your ProcessWindowStyle set to hidden? This is my code working fine:

 Process p=new Process(); p.StartInfo.FileName = filePath;//filePath of the application p.StartInfo.Arguments = launchArguments; p.StartInfo.WindowStyle = (ProcessWindowStyle)ProcessStyle;//Set it to **Normal** p.Start(); 
+2
source share
  System.Diagnostics.Process.Start(FileName,args); 

For example,

  System.Diagnostics.Process.Start("iexplore.exe",Application.StartupPath+ "\\Test.xml"); 
+1
source share

All Articles