3232#ifdef PLATFORM_WINDOWS
3333 #include < windows.h>
3434 #include < shellapi.h>
35+ #include < shlwapi.h>
3536 #include < synchapi.h>
3637 #include < sysinfoapi.h>
3738 #include < winnetwk.h>
@@ -1468,6 +1469,33 @@ namespace lsp
14681469
14691470 static status_t run_program (const LSPString *path, const LSPString *args)
14701471 {
1472+ // Check that executable file exists
1473+ LSPString xpath;
1474+ LPCWSTR ppath = path->get_utf16 ();
1475+ if (!PathFileExistsW (ppath))
1476+ {
1477+ // Try .EXE and .COM extensions
1478+ if (path->ends_with_ascii_nocase (" .exe" ))
1479+ return STATUS_NOT_FOUND;
1480+ if (path->ends_with_ascii_nocase (" .com" ))
1481+ return STATUS_NOT_FOUND;
1482+ // Try ".EXE"
1483+ if (!xpath.set (path))
1484+ return STATUS_NO_MEM;
1485+ if (!xpath.append_ascii (" .exe" ))
1486+ return STATUS_NO_MEM;
1487+ ppath = xpath.get_utf16 ();
1488+ if (!PathFileExistsW (ppath))
1489+ {
1490+ xpath.set_length (xpath.length () - 4 );
1491+ if (!xpath.append_ascii (" .com" ))
1492+ return STATUS_NO_MEM;
1493+ ppath = xpath.get_utf16 ();
1494+ if (!PathFileExistsW (ppath))
1495+ return STATUS_NOT_FOUND;
1496+ }
1497+ }
1498+
14711499 // Launch child process
14721500 STARTUPINFOW si;
14731501 PROCESS_INFORMATION pi;
@@ -1484,7 +1512,7 @@ namespace lsp
14841512
14851513 // Create process
14861514 if (!::CreateProcessW (
1487- path-> get_utf16 (), // Module name (use command line)
1515+ ppath, // Module name (use command line)
14881516 str_args, // Command line
14891517 NULL , // Process handle not inheritable
14901518 NULL , // Thread handle not inheritable
@@ -1548,14 +1576,6 @@ namespace lsp
15481576 lsp_trace (" %s" , program.get_utf8 ());
15491577 if ((res = run_program (&program, args)) == STATUS_OK)
15501578 return res;
1551- if (!program.ends_with_ascii_nocase (" .exe" ))
1552- {
1553- if (!program.append_ascii (" .exe" , 4 ))
1554- return STATUS_NO_MEM;
1555- lsp_trace (" %s" , program.get_utf8 ());
1556- if ((res = run_program (&program, args)) == STATUS_OK)
1557- return res;
1558- }
15591579 }
15601580
15611581 start = found + 1 ;
0 commit comments