0
私はC#アプリケーションでシェルコマンドを実行するには、次のコードを使用してい
:ProcessStartInfoとあるUseShellExecuteの使用
私は「IPCONFIG」または「whoamiは」のようなコマンドを入力すると、それが動作try
{
Process prc = new Process();
prc.StartInfo = new ProcessStartInfo();
prc.StartInfo.FileName = filename;
prc.StartInfo.Arguments = arg;
prc.StartInfo.UseShellExecute = false;
prc.StartInfo.RedirectStandardOutput = true;
prc.Start();
prc.StandardOutput.BaseStream.CopyTo(stream);
prc.WaitForExit();
} catch (Exception e){
Console.WriteLine("{0} Exception caught.", e);
}
。私は例えば「DIR」を入力すると、しかし、私は得る:
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
任意のアイデアなぜですか?ここのトリックは何ですか?
は、実行可能ファイルまたはcmd.exe内のコマンドですか? whoamと同じです... – idontcare
@idontcareはい、これらは両方とも '%Windir%\ System32 \ 'にある' exe'ファイルです。コマンドラインから(例えば): 'where ipconfig'、' where whoami'を使って簡単に確認できます。この場合、 'where dir'はファイルが見つからないことを伝えます – Jcl