2016-07-01 1 views
-1

私は、コマンドプロンプトを開き、次のコードを実行しようとしていますが、クロムを開き、パラメータを渡し、ブラウザがコマンドから開く必要がwww.google.comオープンブラウザは

に移動するC#のコードを使用してプロンプトプロンプト。

引数を渡すときに/ cを使用する必要があることは知っています。

私が試してみました次:

string arguments = "/c " + "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe \"" + " www.google.com"; 
string arguments = "/c " + "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe " + "www.google.com"; 

ブラウザが開いていないとパラメータを渡していない理由を任意のアイデア?

コード

 public void ExecuteCmd() 
     { 

      int exitCode; 
      string arguments ="/c " + @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe " + "www.google.com"; 
      // Prepare the process to run 
      ProcessStartInfo start = new ProcessStartInfo(); 
      // Enter in the command line arguments, everything you would enter after the executable name itself 
      start.Arguments = arguments; 

      start.UseShellExecute = false; 
      start.RedirectStandardOutput = true; 
      // Enter the executable to run, including the complete path 
      start.FileName = @"C:\Windows\system32\cmd.exe"; 
      // Do you want to show a console window? 
      start.WindowStyle = ProcessWindowStyle.Hidden; 
      start.CreateNoWindow = true; 

      // Run the external process & wait for it to finish 
      using (Process proc = Process.Start(start)) 
      { 
       string output = proc.StandardOutput.ReadToEnd(); 
       proc.WaitForExit(); 
       // Retrieve the app's exit code 
       exitCode = proc.ExitCode; 
      } 
     } 
ここ

それは私がそれを手動で行う場合は次のようになります。 Chromeを開き、パラメータを渡します。

enter image description here

+0

:、コマンドでこれはと等しくなるよう求めている

string arguments = @"/c """"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" http://www.google.de""" 

引数を渡します。このスイッチは、コマンドの実行後にコマンドプロンプトが終了することを意味します。 'cmd /?' –

+0

メインコードをコピーして貼り付け、 'arguments'を最初に指定した 'arguments'の最初の例に置き換えると、それはうまく動作します。 (メインコード 'arguments'の問題と2番目の 'arguments'の例は、パスにスペースが含まれているために必要なchrome.exeへのパスの周りに余分な引用符がないことです)。 –

+0

@RufusL少なくともWindows 7では、 '/ c'または'/k'のどちらかを使う必要があります。そうしないと何も起こりません。それが 'cmd /? '私は知らないかもしれませんが、これはWin 8または10で変更された可能性があります。 – Martin

答えて

0

使用この:あなたは '/ C' を使用する必要はありません

C:\>cmd /c ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" http://www.google.de" 
+0

マーティンに感謝します。それはうまくいった。 – Apollo

関連する問題