2010-08-11 51 views
7

我一直在尝试从C#应用程序启动应用程序,但无法正常启动。在cmd中,应用程序和参数启动一个显示输出的小窗口,然后将应用程序最小化到系统托盘中。C#使用多个参数启动应用程序

使用下面的代码从C#应用程序启动应用程序会导致进程出现在任务管理器中,但没有其他任何东西,没有输出窗口,也没有系统托盘图标。可能是什么问题?

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

也尝试过使用

Process.Start(Filename, args) 

也没有工作通过以下

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

。真的很感谢有关如何解决这个问题的任何帮助。

更新: 我认为这个问题也许多个参数将被传递到过程

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

问候

+0

尝试将参数括在单引号中。 – leppie 2010-08-11 08:22:21

+0

@leppie无变化 – artsim 2010-08-11 08:38:15

回答

1
 System.Diagnostics.Process.Start(FileName,args); 

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

我曾试过,但它仍然无法正常工作 – artsim 2010-08-11 08:39:32

7

我不查看代码中的任何错误。我写了一个小程序,打印出它的参数传递给控制台

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

,然后我已经把它放在C:作为应用“PrintingArgs.exe”的名字,所以我写了另外一个,执行第一个:

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(); 

这给出了数字列表的所需输出。调用PrintingArgs的应用程序在到达p.Start()时退出,这可以通过使用p.WaitForExit();或仅使用Console.Read();来避免。 此外我还使用p.UseShellExecutep.CreateNoWindow。只有在

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

使得PrintingArgs应用程序不显示窗口(即使我只放p.CreateNoWindow = true它显示了一个窗口)的情况。

现在我想到,也许你的错误传递参数,并使其他程序失败并立即关闭,或者你没有指向正确的文件。检查路径和名称,以查找可能遗漏的任何错误。 此外,使用

Process.Start(fileName, args); 

不使用你设置了的StartInfo的信息到你的流程实例。

希望这将帮助, 问候

2

具有u设置你的ProcessWindowStyle为隐藏? 这是我的代码,做工精细:

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(); 
4

不知道是否有人依然遵循着这一点,但这里是我想出了。

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); 
} 

在字符串中添加空格允许将两个参数传递到我想运行的程序中。执行代码后程序运行没有问题。