Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit 28b0720

Browse files
committed
Clean up and improve install-directory locating
Another unclear edge case where UIforETW can't find the WPT install location was reported. An extraneous "else" probably made this problem worse, but in addition to removing that this change also cleans up the code and adds the reading of another registry key. This should resolve issue #159.
1 parent 46bf2be commit 28b0720

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

UIforETW/UIforETWDlg.cpp

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,46 +337,71 @@ void CUIforETWDlg::CheckSymbolDLLs()
337337

338338
void CUIforETWDlg::GetInstallFolder()
339339
{
340-
// The WPT installer is always a 32-bit installer, so we look for it in
340+
// The WPT installer is (was?) always a 32-bit installer, so we look for it in
341341
// ProgramFilesX86 / WOW6432Node, on 32-bit and 64-bit operating systems.
342342
wpt10Dir_ = ReadRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v10.0", L"InstallationFolder", true);
343343
if (!wpt10Dir_.empty())
344344
{
345345
EnsureEndsWithDirSeparator(wpt10Dir_);
346346
wpt10Dir_ += L"Windows Performance Toolkit\\";
347+
if (!PathFileExists((wpt10Dir_ + L"xperf.exe").c_str()))
348+
wpt10Dir_.clear();
347349
}
348350

349-
// Look for alternate install paths if needed.
351+
// Some users (issue #159) reported that the registry key above doesn't work,
352+
// and that this registry key should be used instead.
353+
if (wpt10Dir_.empty())
354+
{
355+
// Other sources suggest looking here:
356+
// HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots
357+
// https://stackoverflow.com/questions/35119223/how-to-programmatically-detect-and-locate-the-windows-10-sdk/35121768#35121768
358+
wpt10Dir_ = ReadRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\WOW6432Node\\Microsoft\\Windows Kits\\Installed Roots", L"KitsRoot10", true);
359+
EnsureEndsWithDirSeparator(wpt10Dir_);
360+
wpt10Dir_ += L"Windows Performance Toolkit\\";
361+
if (!PathFileExists((wpt10Dir_ + L"xperf.exe").c_str()))
362+
wpt10Dir_.clear();
363+
}
364+
365+
// Look for alternate install paths if needed. This was needed in 2023 for
366+
// when UIforETW installed WPT without first installing the SDK, causing WPT to
367+
// be installed into the 64-bit program files directory, but with no
368+
// InstallationFolder reg key. It's not clear whether KitsRoot10 resolves this.
369+
const wchar_t* const suffix = L"\\Windows Kits\\10\\Windows Performance Toolkit\\";
370+
std::wstring windowsKits86Dir;
350371
{
351-
const wchar_t* const suffix = L"\\Windows Kits\\10\\Windows Performance Toolkit\\";
352372
wchar_t* progFilesx86Dir = nullptr;
353373
if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, 0, nullptr, &progFilesx86Dir)))
354374
std::terminate();
355-
std::wstring windowsKits86Dir = progFilesx86Dir;
375+
windowsKits86Dir = progFilesx86Dir;
356376
CoTaskMemFree(progFilesx86Dir);
357377
windowsKits86Dir += suffix;
378+
}
358379

380+
std::wstring windowsKitsDir;
381+
{
359382
wchar_t* progFilesDir = nullptr;
360383
if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_ProgramFiles, 0, nullptr, &progFilesDir)))
361384
std::terminate();
362-
std::wstring windowsKitsDir = progFilesDir;
385+
windowsKitsDir = progFilesDir;
363386
CoTaskMemFree(progFilesDir);
364387
windowsKitsDir += suffix;
388+
}
365389

366-
// If the registry entries were unavailable, fall back to assuming their installation directory.
367-
// Starting with the 22H2 SDK this is the ProgramFiles directory rather than ProgramFilesX86
368-
if (wpt10Dir_.empty())
369-
{
390+
// If the registry entries were unavailable, fall back to assuming their installation directory.
391+
// Starting with the 22H2 SDK this is the ProgramFiles directory rather than ProgramFilesX86
392+
if (wpt10Dir_.empty())
393+
{
394+
wpt10Dir_ = windowsKitsDir;
395+
}
396+
397+
// If xperf.exe doesn't exist in wpt10Dir_ and it does exist in one of the two
398+
// default paths then switch to that.
399+
if (!PathFileExists((wpt10Dir_ + L"xperf.exe").c_str()))
400+
{
401+
if (PathFileExists((windowsKits86Dir + L"xperf.exe").c_str()))
402+
wpt10Dir_ = windowsKits86Dir;
403+
else if (PathFileExists((windowsKitsDir + L"xperf.exe").c_str()))
370404
wpt10Dir_ = windowsKitsDir;
371-
}
372-
// If xperf.exe doesn't exist in wpt10Dir_ and it does exist elsewhere, switch to that.
373-
else if (!PathFileExists((wpt10Dir_ + L"xperf.exe").c_str()))
374-
{
375-
if (PathFileExists((windowsKits86Dir + L"xperf.exe").c_str()))
376-
wpt10Dir_ = windowsKits86Dir;
377-
else if (PathFileExists((windowsKitsDir + L"xperf.exe").c_str()))
378-
wpt10Dir_ = windowsKitsDir;
379-
}
380405
}
381406
}
382407

0 commit comments

Comments
 (0)