@@ -14,6 +14,7 @@ import var Foundation.NSLocalizedDescriptionKey
1414
1515#if os(Windows)
1616import Foundation
17+ import WinSDK. core. sysinfo
1718#endif
1819
1920@_implementationOnly import TSCclibc
@@ -350,11 +351,32 @@ public final class Process {
350351 pathString: ProcessEnv . path,
351352 currentWorkingDirectory: cwdOpt
352353 )
354+ #if os(Windows)
355+ var searchPaths = [ String] ( )
356+ let buffer = UnsafeMutablePointer< String> . allocate( capacity: 260 )
357+
358+ // The 32-bit Windows system directory
359+ GetSystemDirectoryW ( buffer, 260 )
360+ searchPaths += buffer. pointee
361+
362+ // The 16-bit Windows system directory
363+ searchPaths += " \( ProcessEnv . vars [ " systemdrive " ] ?? " C: " ) \\ System "
364+
365+ // The Windows directory
366+ GetWindowsDirectoryW ( buffer, 260 )
367+ searchPaths += buffer. pointee
368+
369+ searchPaths. append ( contentsOf: envSearchPaths)
370+ #else
371+ let searchPaths = envSearchPaths
372+ #endif
373+ // Lookup and cache the executable path.
353374 let value = lookupExecutablePath (
354375 filename: program,
355376 currentWorkingDirectory: cwdOpt,
356- searchPaths: envSearchPaths
377+ searchPaths: searchPaths
357378 )
379+ Process . validatedExecutablesMap [ program] = value
358380 return value
359381 }
360382 // This should cover the most common cases, i.e. when the cache is most helpful.
0 commit comments