@@ -14,6 +14,7 @@ import var Foundation.NSLocalizedDescriptionKey
1414
1515#if os(Windows)
1616import Foundation
17+ import WinSDK
1718#endif
1819
1920@_implementationOnly import TSCclibc
@@ -471,10 +472,26 @@ public final class Process {
471472 pathString: ProcessEnv . path,
472473 currentWorkingDirectory: cwdOpt
473474 )
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)
474491 let value = lookupExecutablePath (
475492 filename: program,
476493 currentWorkingDirectory: cwdOpt,
477- searchPaths: envSearchPaths
494+ searchPaths: searchPaths
478495 )
479496 return value
480497 }
0 commit comments