question

38177934 avatar image
0 Votes"
38177934 asked SongZhu-MSFT answered

ShellExecuteEx run the string "findstr / c:"[SR]" %windir%\logs\cbs\cbs.log > sfcdetails.txt"

How to call ShellExecuteEx function to execute the "findstr / c:"[SR]" %windir%\logs\cbs\cbs.log > sfcdetails.txt"

windows-api
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SongZhu-MSFT avatar image
0 Votes"
SongZhu-MSFT answered

You can refer to the following code:


 #include <windows.h>

 int main()
 {
     SHELLEXECUTEINFOA lpExecInfo{};
     lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
     lpExecInfo.lpFile = "cmd.exe";
     lpExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
     lpExecInfo.hwnd = NULL;
     lpExecInfo.lpVerb = NULL;
     lpExecInfo.lpParameters = "/c findstr /c:\"[SR]\" %windir%\\logs\\cbs\\cbs.log > sfcdetails.txt";
     lpExecInfo.lpDirectory = NULL;
     lpExecInfo.nShow = SW_SHOWNORMAL;
     BOOL b = ShellExecuteExA(&lpExecInfo);
    
     if(lpExecInfo.hProcess) WaitForSingleObject(lpExecInfo.hProcess, INFINITE);
    
     if (lpExecInfo.hProcess)
     {
         TerminateProcess(lpExecInfo.hProcess, 0);
         CloseHandle(lpExecInfo.hProcess);
     }
     return 0;
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.