@@ -12,6 +12,7 @@ import class Foundation.ProcessInfo
12
12
13
13
#if os(Windows)
14
14
import Foundation
15
+ import WinSDK. core. sysinfo
15
16
#endif
16
17
17
18
@_implementationOnly import TSCclibc
@@ -324,9 +325,28 @@ public final class Process: ObjectIdentifierProtocol {
324
325
pathString: ProcessEnv . path,
325
326
currentWorkingDirectory: localFileSystem. currentWorkingDirectory
326
327
)
328
+ #if os(Windows)
329
+ var searchPaths = [ String] ( )
330
+ let buffer = UnsafeMutablePointer< String> . allocate( capacity: 260 )
331
+
332
+ // The 32-bit Windows system directory
333
+ GetSystemDirectoryW ( buffer, 260 )
334
+ searchPaths += buffer. pointee
335
+
336
+ // The 16-bit Windows system directory
337
+ searchPaths += " \( ProcessEnv . vars [ " systemdrive " ] ?? " C: " ) \\ System "
338
+
339
+ // The Windows directory
340
+ GetWindowsDirectoryW ( buffer, 260 )
341
+ searchPaths += buffer. pointee
342
+
343
+ searchPaths. append ( contentsOf: envSearchPaths)
344
+ #else
345
+ let searchPaths = envSearchPaths
346
+ #endif
327
347
// Lookup and cache the executable path.
328
348
let value = lookupExecutablePath (
329
- filename: program, searchPaths: envSearchPaths )
349
+ filename: program, searchPaths: searchPaths )
330
350
Process . validatedExecutablesMap [ program] = value
331
351
return value
332
352
}
0 commit comments