C#はExeを呼び出す
================================================== ========
クラスProgram
{
static void DisplayBitArrAY()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = @ "D:\ Program Files(x86)\ Tencent \ QQ \ Bin \ QQ.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = "你好、北京欢迎你!";
{
static void DisplayBitArrAY()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = @ "D:\ Program Files(x86)\ Tencent \ QQ \ Bin \ QQ.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = "你好、北京欢迎你!";
process.Start(); // process.Close();
process.WaitForExit(); // if(process.HasExited)
Console.WriteLine( "complete:{0}"、process.ExitCode);
}
static void Main(string [] args)
{
DisplayBitArrAY();
}
}
Console.WriteLine( "complete:{0}"、process.ExitCode);
}
static void Main(string [] args)
{
DisplayBitArrAY();
}
}
================================================== ============
プログラムを作成するとき、実行可能なプログラムを呼び出すためによく使用されます。この記事では、exeを呼び出すC#の方法を簡単に紹介します。C#では、プロセス操作はProcessクラスを介して実行されます。ProcessクラスはSystem.Diagnosticsパッケージに含まれています。
例1
System.Diagnosticsを使用します。
プロセスp = Process.Start( "notepad.exe");
p.WaitForExit(); //キー、続行する前に外部プログラムが終了するのを待ちます
p.WaitForExit(); //キー、続行する前に外部プログラムが終了するのを待ちます
メモ帳プログラムは上記のコードで呼び出すことができます。システムプログラムを呼び出さない場合は、フルパスを入力する必要があります。
例2
cmdプログラムを呼び出す必要がある場合、上記の呼び出し方法を使用すると、迷惑な黒いウィンドウがポップアップ表示されます。それを排除したい場合は、より詳細な設定を行う必要があります。
ProcessクラスのStartInfoプロパティには、いくつかのプロセス起動情報が含まれていますが、そのうちのいくつかはより重要です。
FileName実行可能プログラムファイル名
文字列の形式で入力された引数プログラムパラメータ
CreateNoWindowはウィンドウを作成する必要はありません
UseShellExecuteシステムシェルによってプログラムを呼び出すかどうか
CreateNoWindowはウィンドウを作成する必要はありません
UseShellExecuteシステムシェルによってプログラムを呼び出すかどうか
上記のパラメータを使用して、迷惑な黒い画面を非表示にすることができます
System.Diagnostics.Process exep = new System.Diagnostics.Process();
exep.StartInfo.FileName = binStr;
exep.StartInfo.Arguments = cmdStr;
exep.StartInfo.CreateNoWindow = true;
exep.StartInfo.UseShellExecute = false;
exep。 Start();
exep.WaitForExit(); //キー、外部プログラムが終了するのを待ってから続行します
exep.StartInfo.FileName = binStr;
exep.StartInfo.Arguments = cmdStr;
exep.StartInfo.CreateNoWindow = true;
exep.StartInfo.UseShellExecute = false;
exep。 Start();
exep.WaitForExit(); //キー、外部プログラムが終了するのを待ってから続行します
または
System.Diagnostics.Process exep = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = binStr;
startInfo.Arguments = cmdStr;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
exep.Start(startInfo);
exep.WaitForExit(); //キー、続行する前に外部プログラムが終了するのを待ちます