ShellExecute Memory Usage

I’m using ShellExecute to launch a chosen exe in my D13 VCL application. While it does work, I’ve noticed if the app I launch is acrobat.exe, then in Task Manager my app lists a bunch of Adobe processes and my app’s memory usage skyrockets. Other apps I launch don’t show this behaviour.

I’ve used ShellExecute in another (XE) application for years and it doesn’t seem to have that issue. I did try ShellExecuteEx and it did the same. What am I overlooking here?

I use CreateProcess when that sort of thing happens. Cleaner exit

// Build the command line to run the batch file using cmd.exe with the /c parameter

// which executes the command and then terminates.

// The command must be mutable (not a PChar literal) and include full paths if needed.

CmdLine := Format(‘cmd.exe /c “%s” %s’, [BatchFileName, Parameters]);

// Create the process using the CREATE_NO_WINDOW flag

if CreateProcess(

nil, // Application Name (use CmdLine instead)

PChar(CmdLine), // Command Line (must be a mutable string)

nil, // Process Security Attributes

nil, // Thread Security Attributes

False, // Inherit Handles

CREATE_NO_WINDOW, // Creation Flags: This is the crucial flag

nil, // Environment

nil, // Current Directory

StartupInfo, // Startup Info

ProcessInfo // Process Info

) then

begin

// Optional: Wait for the batch file to complete

// WaitForSingleObject(ProcessInfo.hProcess, INFINITE);

// Close process and thread handles

CloseHandle(ProcessInfo.hProcess);

CloseHandle(ProcessInfo.hThread);

end

else

begin

// Handle error (e.g., show an error message)

MessageBox(0, PChar('Failed to run batch file: ’ + IntToStr(GetLastError)), ‘Error’, MB_OK or MB_ICONERROR);

end;

Alan McDonald

Still the same issue using CreateProcess unfortunately.

And if that works, putting the command in a .bat file and executing that instead might give you a clue as to what is going on. Start directory, environment variables, etc. etc.

Is there a problem with acrobat? If you launch acrobat.exe from the command line with identical parameters, what happens?

Acrobat starts with ShellExecute and CreateProcess, but the memory attributed to my launcher app increases and Task Manager shows the Adobe processes under my app for some reason,

This is normal, task manager is showing the process tree - if you kill your application then those child processes get killed too.

I wouldn’t worry about the memory issue, it’s just a showing the total usage of the applications in that branch of a tree - you will see the same thing for multiprocess apps like chrome.

Ah, fair enough. My app can also close, minimise, restore, maximise, move, resize and press buttons on the targeted exe and that’s all working now. The open command just had me concerned that I was doing something wrong.I just need to finish off the OSC control side of it now.