Question

I want my MFC-C++ program to open cmd.exe and run 7-zip in command line which takes in several parameters.

    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!"));
}

If I just execute "C:\tmp\7zip-command line\7za920\7za" e C:\cpp\zipping*.tar *. png -r -o"C:\tmp\7zip-command line\7za920" by pasting it in command window, it works fine. But, I am not able to execute the same through my program. Please note command-line version of 7-zip, "7za.exe" is in the folder path "C:\tmp\7zip-command line\7za920" I would like to also know if it's correct decision that I have made to use ShellExecuteEx() instead of CreateProcess() and is there any other way to solve my problem. Please let me know. Thanks in advance.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top