diff --git a/Sources/TSCBasic/Process.swift b/Sources/TSCBasic/Process.swift index 97358a56..e13b7f2f 100644 --- a/Sources/TSCBasic/Process.swift +++ b/Sources/TSCBasic/Process.swift @@ -14,6 +14,7 @@ import var Foundation.NSLocalizedDescriptionKey #if os(Windows) import Foundation +import WinSDK #endif @_implementationOnly import TSCclibc @@ -350,10 +351,26 @@ public final class Process { pathString: ProcessEnv.path, currentWorkingDirectory: cwdOpt ) + var searchPaths: [AbsolutePath] = [] +#if os(Windows) + var buffer = Array(repeating: 0, count: Int(MAX_PATH + 1)) + // The 32-bit Windows system directory + if GetSystemDirectoryW(&buffer, .init(buffer.count)) > 0 { + searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self))) + } + if GetWindowsDirectoryW(&buffer, .init(buffer.count)) > 0 { + let windowsDirectory = String(decodingCString: buffer, as: UTF16.self) + // The 16-bit Windows system directory + searchPaths.append(AbsolutePath("\(windowsDirectory)\\System")) + // The Windows directory + searchPaths.append(AbsolutePath(windowsDirectory)) + } +#endif + searchPaths.append(contentsOf: envSearchPaths) let value = lookupExecutablePath( filename: program, currentWorkingDirectory: cwdOpt, - searchPaths: envSearchPaths + searchPaths: searchPaths ) return value }