@@ -14,6 +14,7 @@ import var Foundation.NSLocalizedDescriptionKey
14
14
15
15
#if os(Windows)
16
16
import Foundation
17
+ import WinSDK
17
18
#endif
18
19
19
20
@_implementationOnly import TSCclibc
@@ -471,10 +472,26 @@ public final class Process {
471
472
pathString: ProcessEnv . path,
472
473
currentWorkingDirectory: cwdOpt
473
474
)
475
+ var searchPaths : [ AbsolutePath ] = [ ]
476
+ #if os(Windows)
477
+ var buffer = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH + 1 ) )
478
+ // The 32-bit Windows system directory
479
+ if GetSystemDirectoryW ( & buffer, . init( buffer. count) ) > 0 {
480
+ searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
481
+ }
482
+ if GetWindowsDirectoryW ( & buffer, . init( buffer. count) ) > 0 {
483
+ let windowsDirectory = String ( decodingCString: buffer, as: UTF16 . self)
484
+ // The 16-bit Windows system directory
485
+ searchPaths. append ( AbsolutePath ( " \( windowsDirectory) \\ System " ) )
486
+ // The Windows directory
487
+ searchPaths. append ( AbsolutePath ( windowsDirectory) )
488
+ }
489
+ #endif
490
+ searchPaths. append ( contentsOf: envSearchPaths)
474
491
let value = lookupExecutablePath (
475
492
filename: program,
476
493
currentWorkingDirectory: cwdOpt,
477
- searchPaths: envSearchPaths
494
+ searchPaths: searchPaths
478
495
)
479
496
return value
480
497
}
0 commit comments