Skip to content

Commit

Permalink
[PT Run] Retry on unavailable desktop (microsoft#17864)
Browse files Browse the repository at this point in the history
* retry on unavailable desktop

* improved code
  • Loading branch information
davidegiacometti authored Apr 27, 2022
1 parent 2a7afa3 commit 0549b02
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/common/utils/elevation.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,25 @@ namespace
inline bool GetDesktopAutomationObject(REFIID riid, void** ppv)
{
CComPtr<IShellView> spsv;
if (!FindDesktopFolderView(IID_PPV_ARGS(&spsv)))

// Desktop may not be available on startup
auto attempts = 5;
for (auto i = 1; i <= attempts; i++)
{
return false;
if (FindDesktopFolderView(IID_PPV_ARGS(&spsv)))
{
break;
}

Logger::warn(L"FindDesktopFolderView() failed attempt {}", i);

if (i == attempts)
{
Logger::warn(L"FindDesktopFolderView() max attempts reached");
return false;
}

Sleep(3000);
}

CComPtr<IDispatch> spdispView;
Expand Down

0 comments on commit 0549b02

Please sign in to comment.