@@ -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
@@ -350,10 +351,26 @@ public final class Process {
350
351
pathString: ProcessEnv . path,
351
352
currentWorkingDirectory: cwdOpt
352
353
)
354
+ var searchPaths : [ AbsolutePath ] = [ ]
355
+ #if os(Windows)
356
+ var buffer = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH + 1 ) )
357
+ // The 32-bit Windows system directory
358
+ if GetSystemDirectoryW ( & buffer, . init( buffer. count) ) > 0 {
359
+ searchPaths. append ( AbsolutePath ( String ( decodingCString: buffer, as: UTF16 . self) ) )
360
+ }
361
+ if GetWindowsDirectoryW ( & buffer, . init( buffer. count) ) > 0 {
362
+ let windowsDirectory = String ( decodingCString: buffer, as: UTF16 . self)
363
+ // The 16-bit Windows system directory
364
+ searchPaths. append ( AbsolutePath ( " \( windowsDirectory) \\ System " ) )
365
+ // The Windows directory
366
+ searchPaths. append ( AbsolutePath ( windowsDirectory) )
367
+ }
368
+ #endif
369
+ searchPaths. append ( contentsOf: envSearchPaths)
353
370
let value = lookupExecutablePath (
354
371
filename: program,
355
372
currentWorkingDirectory: cwdOpt,
356
- searchPaths: envSearchPaths
373
+ searchPaths: searchPaths
357
374
)
358
375
return value
359
376
}
0 commit comments