Skip to content

Commit 35af768

Browse files
committed
Shell (Windows): improves performance of Windows PowerShell version detection
1 parent 22c4620 commit 35af768

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/detection/terminalshell/terminalshell.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define _PATH_LOCALBASE "/usr/pkg"
2020
#elif _WIN32
2121

22+
#include "common/windows/registry.h"
2223
#include "common/windows/version.h"
2324
#include <windows.h>
2425

@@ -248,6 +249,12 @@ static bool getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version) {
248249
return true;
249250
}
250251

252+
FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
253+
if (ffRegOpenSubkeyForRead(ffRegGetRootKeyHandle(HKEY_LOCAL_MACHINE), L"SOFTWARE\\Microsoft\\PowerShell\\3\\PowerShellEngine", &hKey, NULL) && ffRegReadStrbuf(hKey, L"PowerShellVersion", version, NULL)) {
254+
return true;
255+
}
256+
257+
// Extremely slow
251258
return ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-NoLogo", "-NoProfile", "-Command", "$PSVersionTable.PSVersion.ToString()", NULL }) == NULL;
252259
}
253260
#endif

0 commit comments

Comments
 (0)