1

我希望我的 MFC-C++ 程序打开 cmd.exe 并在命令行中运行 7-zip,它接受几个参数。

    SHELLEXECUTEINFO ShRun = {0};
ShRun.cbSize = sizeof(SHELLEXECUTEINFO);
ShRun.fMask = SEE_MASK_NOCLOSEPROCESS;
ShRun.hwnd = NULL;
ShRun.lpVerb = NULL;
ShRun.lpFile = _T("c:\\windows\\System32\\cmd.exe");
ShRun.lpParameters = _T("C:\\tmp\\7zip-command line\\7za920\\7za e C:\cpp\zipping\*.tar *.png -r -o"C:\tmp\7zip-command line\7za920"");
ShRun.lpDirectory = _T("c:\\windows\\System32");
ShRun.nShow = SW_SHOW;
ShRun.hInstApp = NULL;

// Execute the file with the parameters
if (!ShellExecuteEx(&ShRun))
{
    MessageBox(_T("Unable to open file!"));
}

如果我只是执行 "C:\tmp\7zip-command line\7za920\7za" e C:\cpp\zipping*.tar *. png -r -o"C:\tmp\7zip-command line\7za920" 通过将其粘贴到命令窗口中,它可以正常工作。但是,我无法通过我的程序执行相同的操作。请注意 7-zip 的命令行版本,“7za.exe”位于文件夹路径“C:\tmp\7zip-command line\7za920”中我还想知道我是否做出了正确的决定使用ShellExecuteEx() 而不是 CreateProcess() ,还有其他方法可以解决我的问题。请告诉我。提前致谢。

4

0 回答 0