我目前正在与
reg.exe
我正在创建一个流程
reg.exe
作为
Process.FileName
.
当我试图像下面这样执行reg.exe时
REG EXPORT HKLM\\SOFTWARE\\Intel\\IntelAMTUNS D:\\Backups\\Test.reg
但只要我这么做
REG EXPORT HKLM\\SOFTWARE\\Intel\\IntelAMTUNS D:\\Backups\\Backup folder 1\\Test.reg
什么都没发生——我知道为什么!目标路径未加引号。只要我这么做,一切都会好起来的。
DirectoryInfo
。当我用引号作为字符串传递路径时,例如
DirectoryInfo targetFolder = new DirectoryInfo("\"D:\\Backups\\Backup folder 1\\Test.reg\"")
不支持给定路径的格式
.
有什么方法可以将路径放在引号中,并且仍然使用DirecotryInfo吗?
下面是一些示例代码:
DirectoryInfo backupPath = new DirectoryInfo("D:\\Backups\\Backup folder 1\\Test.reg");
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "reg.exe";
startInfo.CreateNoWindow = true;
startInfo.Arguments = "REG EXPORT HKLM\\SOFTWARE\\Intel\\IntelAMTUNS " + backupPath.FullName;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
当我运行这段代码时,什么都没有发生,也没有错误或异常。reg文件本身也没有创建。
DirectoryInfo backupPath = new DirectoryInfo("\"D:\\Backups\\Backup folder 1\\Test.reg\"");
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "reg.exe";
startInfo.CreateNoWindow = true;
startInfo.Arguments = "REG EXPORT HKLM\\SOFTWARE\\Intel\\IntelAMTUNS " + backupPath.FullName;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
我得到一个
System.NotSupportedException
告诉我“
“但我实际上需要将路径加引号,否则命令本身将无法工作。。。