我有这段代码:
private void SysInfo32()
{
Process proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "systeminfo.exe";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.Arguments = "systeminfo.exe>" + "\"" + contentDirectory + "\\systeminfo.txt" + "\"";
proc.Start();
proc.WaitForExit();
proc.Close();
}
contentDirectory是:C:\ Users \ bout0_000 \ AppData \ Local \ Diagnostic_Tool_Blue_Screen \ Diagnostic Tool Blue Screen \ SF_28-07-13
我希望systeminfo.txt在里面:SF_28-07-13
但该文件永远不会在此目录中创建。
我使用的参数和msinfo32.exe一样,使用的是Msinfo.exe
private void MsInfo()
{
Process proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "msinfo32.exe";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.Arguments = "/nfo " + "\"" + contentDirectory + "\\msinfo.nfo" + "\"";
proc.Start();
proc.WaitForExit();
proc.Close();
}
所以我不明白它为什么不使用systeminfo.exe?
我使用命令行“>”正如论点从这个网站上看到的那样:
http://www.worldstart.com/generate-a-system-info-text-file/
答案 0 :(得分:5)
试试这个
private void SysInfo32()
{
Process proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WorkingDirectory = contentDirectory;
proc.StartInfo.Arguments = "/C systeminfo.exe> sysinfo.txt";
proc.Start();
proc.WaitForExit();
proc.Close();
}
为什么你仍然坚持使用那种丑陋的语法来包含带空格的目录,当你可以轻松使用WorkingDirectory属性来获得相同的结果时我不清楚