如何在进程中使用 msinfo32.exe 命令行? [英] How to use msinfo32.exe command lines in a Process?
问题描述
我有这个简单的代码:
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.StartInfo.WorkingDirectory = contentDirectory;
proc.Start();
proc.WaitForExit();
proc.Close();
}
我想在目录 contentDirectory 中创建 msinfo.nfo.contentDirectory 现在是:
I want to create msinfo.nfo in the directory contentDirectory. The contentDirectory now is:
C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_28-07-13
C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_28-07-13
我想在参数中使用变量 contentDirectory 的原因是目录 SF_28-07-13 每天都在变化.明天是 SF_29-07-13
The reason i want to use variable contentDirectory in the arguments is that the directory SF_28-07-13 change every day. Tommorow it will be SF_29-07-13
如果我在参数中做:
proc.StartInfo.Arguments = "/nfo C:\TEST\TEST.NFO" 然后将在 C:\TEST 中创建文件 TEST.NFO
proc.StartInfo.Arguments = "/nfo C:\TEST\TEST.NFO" then the file TEST.NFO will be created in C:\TEST
但是由于某种原因,当我使用 contentDirectory 变量时,我无法在任何地方看到文件 msinfo.nfo.
But for some reason when im using the contentDirectory variable i cant see the file msinfo.nfo anywhere.
相反,我在以下位置看到一个名为 Diagnostic 的奇怪文件名:
Instead i see a strange file name called Diagnostic in the location of:
C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen从 contentDirectory 返回的两个目录
C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen Two directories back from the contentDirectory
诊断文件是 24mb 并且可以,但这不是我想要创建的文件名,也不是在这个位置.
The Diagnostic file is 24mb and its ok but thats not the file name i wanted to create and not in this location.
我在参数中尝试了很多方法,也删除/删除了该行:proc.StartInfo.WorkingDirectory = contentDirectory;
I tried many ways in the Arguments and also removed/deleted the line : proc.StartInfo.WorkingDirectory = contentDirectory;
但没有任何效果.
我还能做什么?
推荐答案
字符串
C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_28-07-13\msinfo.nfo
应该是双引号:
"C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_28-07-13\msinfo.nfo"
与:
proc.StartInfo.Arguments = "/nfo " + "\"" + contentDirectory + "\\msinfo.nfo" + "\"";
这篇关于如何在进程中使用 msinfo32.exe 命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!