2017-05-31 38 views
0

我想將三個參數傳遞給其他EXE項目啓動位置,我成功地做了C但我不能在C#窗口應用程序中做到這一點,請幫助我如何做到這一點?下面的C代碼適用於它如何使用C#windows應用程序將三個參數傳遞給其他「demo.exe」?

#include<stdio.h> 
#include<stdlib.h> 
#include<ctype.h> 
int main() 
{ 
char query[100]; 
int MYNO= 0x1133aa; 
sprintf(query, "demo.exe %x test.bin",MYNO); 
system(query); 
return 0; 
} 
enter code here 

我怎樣寫在C#中的代碼,請幫我:(

+3

[啓動從C#的應用程序(.EXE)η]爲可能的複製(https://stackoverflow.com/questions/240171/launching-an-application-exe-from-c) –

+0

無無其不同,在這裏我想傳遞三個參數到demo.exe並開始,給出鏈接https://stackoverflow.com/questions/240171/launching-an-application-exe-from-c顯示如何啓動一個應用程序使用C# ? – surajbinorkar

+1

在鏈接頁面中搜索*在命令行參數中輸入,在可執行文件名稱本身之後輸入的所有內容* –

回答

0

試試這個:

System.Diagnostics.Process.Start("demo.exe","arguments"); 
+0

It works Thanks A Lot :) – surajbinorkar

0

在Visual Studio中,你也可以做這樣的通過簡單或comandline說法迴避:

static void Main(string[] args) 
{ 
    if (args == null) 
    { 
     Console.WriteLine("args is null"); // Check for null array 
    } 
    else 
    { 
     args=new string[2]; 
     args[0] = "welcome in"; 
     args[1] = "www.overflow.com"; 
     Console.Write("args length is "); 
     Console.WriteLine(args.Length); // Write array length 
     for (int i = 0; i < args.Length; i++) // Loop through array 
     { 
      string argument = args[i]; 
      Console.Write("args index "); 
      Console.Write(i); // Write index 
      Console.Write(" is ["); 
      Console.Write(argument); // Write string 
      Console.WriteLine("]"); 
     } 
    } 
0

看到這裏的文檔:https://msdn.microsoft.com/de-de/library/h6ak8zt5%28v=vs.110%29.aspx

using System; 
using System.Diagnostics; 
using System.ComponentModel; 

namespace MyProcessSample 
{ 
    class MyProcess 
    { 
     // Opens the Internet Explorer application. 
     void OpenApplication(string myFavoritesPath) 
     { 
      // Start Internet Explorer. Defaults to the home page. 
      Process.Start("IExplore.exe"); 

      // Display the contents of the favorites folder in the browser. 
      Process.Start(myFavoritesPath); 
     } 

     // Opens urls and .html documents using Internet Explorer. 
     void OpenWithArguments() 
     { 
      // url's are not considered documents. They can only be opened 
      // by passing them as arguments. 
      Process.Start("IExplore.exe", "www.northwindtraders.com"); 

      // Start a Web page using a browser associated with .html and .asp files. 
      Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm"); 
      Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp"); 
     } 

     // Uses the ProcessStartInfo class to start new processes, 
     // both in a minimized mode. 
     void OpenWithStartInfo() 
     { 
      ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); 
      startInfo.WindowStyle = ProcessWindowStyle.Minimized; 

      Process.Start(startInfo); 

      startInfo.Arguments = "www.northwindtraders.com"; 

      Process.Start(startInfo); 
     } 

     static void Main() 
     { 
      // Get the path that stores favorite links. 
      string myFavoritesPath = 
       Environment.GetFolderPath(Environment.SpecialFolder.Favorites); 

      MyProcess myProcess = new MyProcess(); 

      myProcess.OpenApplication(myFavoritesPath); 
      myProcess.OpenWithArguments(); 
      myProcess.OpenWithStartInfo(); 
     } 
    } 
} 
相關問題