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