I am working on an application in qt where I am required to use ShellExecuteEx to launch an application. I am running a batch file and I need to pass it 2 arguments. The first argument is just a letter, but the second is a path that may or may not contain spaces. No matter what I do, it will not escape the spaces. It seems like including any escaped quotations actually breaks the entire call. I think the issue is with the runas. I'm not 100% sure how it works, but it seems like it is copying the call and running it in an escalated shell. It seems like this process breaks with the added quotations.
Here is my ShellExecute code. I have simplified it to passing in 1 argument, but this still breaks.
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"runas";
ShExecInfo.lpFile = L"test.bat";
ShExecInfo.lpParameters = L"\"test param\"";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
Here is test.bat just for completeness
@echo off
pause
The shell output I get is.
'J:\Repositories\Qt' is not recognized as an internal or external command, operable program or batch file.
The path to the script is
J:\Repositories\Qt Project\debug\test.bat
You can see that the initial command fails because its messing up the original path.
Any idea how to include quotations in the arguments with a runas command like this?