azrael_11 0 Posted December 9, 2018 Hello.. When i execute this command var program_path: string; begin program_path:= c:/myprogram.exe ShellExecute(0, nil, 'cmd.exe', PChar('/C ' + program_path+ ' -fg'), PChar(program_path), SW_HIDE); but when the program_path have a space like a "New folder" var program_path: string; begin program_path:= c:/New Folder/myprogram.exe ShellExecute(0, nil, 'cmd.exe', PChar('/C ' + program_path+ ' -fg'), PChar(program_path), SW_HIDE); Then nothing happens . I try this ShellExecute(0, nil, 'cmd.exe', PChar(AnsiQuotedStr('/C ' + program_path+ ' -fg', Char(34))), PChar(program_path), SW_HIDE); Nothing. Share this post Link to post
dummzeuch 1505 Posted December 9, 2018 You should only quote the program path rather than the whole command line. Share this post Link to post
azrael_11 0 Posted December 9, 2018 34 minutes ago, dummzeuch said: You should only quote the program path rather than the whole command line. I try this ShellExecute(0, nil, 'cmd.exe', PChar(AnsiQuotedStr('/C ' + program_path, Char(34))+ ' -fg'), PChar(program_path), SW_HIDE); Nothing, not working. Share this post Link to post
dummzeuch 1505 Posted December 9, 2018 (edited) 2 hours ago, azrael_11 said: I try this ShellExecute(0, nil, 'cmd.exe', PChar(AnsiQuotedStr('/C ' + program_path, Char(34))+ ' -fg'), PChar(program_path), SW_HIDE); Nothing, not working. You quoted the whole command line, not just the program path. This is what I meant: ShellExecute(0, nil, 'cmd.exe', PChar('/C ' + AnsiQuotedStr(program_path, Char(34))+ ' -fg'), PChar(program_path), SW_HIDE); Edited December 9, 2018 by dummzeuch Share this post Link to post
azrael_11 0 Posted December 9, 2018 41 minutes ago, dummzeuch said: You quoted the whole command line, not just the program path. This is what I meant: ShellExecute(0, nil, 'cmd.exe', PChar('/C ' + AnsiQuotedStr(program_path, Char(34))+ ' -fg'), PChar(program_path), SW_HIDE); That work just fine. Thank you. Share this post Link to post
David Heffernan 2345 Posted December 9, 2018 Pointless to ask ShellExecute to create a cmd process to in turn create another process. Create the other process directly. This is the source of all your problems. 3 Share this post Link to post
azrael_11 0 Posted December 11, 2018 On 12/9/2018 at 5:57 PM, David Heffernan said: Pointless to ask ShellExecute to create a cmd process to in turn create another process. Create the other process directly. This is the source of all your problems. I think you are right about this so i make a process to call that... Thank you. Share this post Link to post
David Heffernan 2345 Posted December 11, 2018 1 hour ago, azrael_11 said: I think you are right about this so i make a process to call that... Thank you. Surely you just call CreateProcess directly 1 Share this post Link to post
A.M. Hoornweg 144 Posted December 17, 2018 On 12/9/2018 at 4:57 PM, David Heffernan said: Pointless to ask ShellExecute to create a cmd process to in turn create another process. Create the other process directly. This is the source of all your problems. ... unless you need to use pipes, environment variables or want to capture the output of a command line program into a file. Then cmd.exe is a real life saver for which there is no real alternative as far as I'm aware. I had precisely that case last week. In an installation routine (inno Setup) I needed to figure out if a set of Microsoft IIS components was installed correctly before allowing the user to continue the installation of my ISAPI webservice. The following one-liner gives that information sorted in a text file. cmd.exe /s /c dism /online /Get-Features /Format:table /English | sort >%tmp%\dismfeatures.txt (Note that on 64-bit systems, this particular example requires calling the 64-bit version of cmd.exe; The 32-bit version of cmd.exe will call the 32-bit version of dism.exe which is totally non-functional on 64-bit operating systems. Google "Wow64DisableWow64FsRedirection" for more info). Share this post Link to post
David Heffernan 2345 Posted December 17, 2018 But none of that complexity is present here. And even if it was, then you'd still use CreateProcess. ShellExecuteEx would have value with the runas verb only. Share this post Link to post
Remy Lebeau 1397 Posted February 8, 2019 On 12/17/2018 at 5:41 AM, David Heffernan said: ShellExecuteEx would have value with the runas verb only. And even that is not needed if you use CreateProcessElevated() instead. Share this post Link to post