[EXPLORER] Execute RunOnce[Ex] before desktop is created (#7143)

CORE-19501
This commit is contained in:
Whindmar Saksit 2024-07-17 12:42:22 +02:00 committed by GitHub
parent 28cb0995e6
commit 738c8fc27c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 14 deletions

View file

@ -154,6 +154,8 @@ StartWithDesktop(IN HINSTANCE hInstance)
buttons to work right) */
HideMinimizedWindows(TRUE);
ProcessRunOnceItems(); // Must be executed before the desktop is created
HANDLE hShellDesktop = NULL;
if (Tray != NULL)
hShellDesktop = DesktopCreateWindow(Tray);
@ -167,6 +169,7 @@ StartWithDesktop(IN HINSTANCE hInstance)
ProcessStartupItems();
DoFinishStartupItems();
}
ReleaseStartupMutex(); // For ProcessRunOnceItems
#endif
if (Tray != NULL)

View file

@ -252,9 +252,12 @@ HRESULT ShutdownShellServices(HDPA hdpa);
* startup.cpp
*/
VOID ReleaseStartupMutex();
VOID ProcessRunOnceItems();
BOOL DoStartStartupItems(ITrayWindow *Tray);
INT ProcessStartupItems(VOID);
BOOL DoFinishStartupItems(VOID);
INT ProcessStartupItems(BOOL bRunOnce);
static inline INT ProcessStartupItems() { return ProcessStartupItems(FALSE); }
static inline VOID DoFinishStartupItems() { ReleaseStartupMutex(); }
/*
* trayprop.h

View file

@ -450,7 +450,7 @@ AutoStartupApplications(INT nCSIDL_Folder)
return TRUE;
}
INT ProcessStartupItems(VOID)
INT ProcessStartupItems(BOOL bRunOnce)
{
/* TODO: ProcessRunKeys already checks SM_CLEANBOOT -- items prefixed with * should probably run even in safe mode */
BOOL bNormalBoot = GetSystemMetrics(SM_CLEANBOOT) == 0; /* Perform the operations that are performed every boot */
@ -478,11 +478,16 @@ INT ProcessStartupItems(VOID)
*/
res = TRUE;
if (res && bNormalBoot)
ProcessRunOnceEx(HKEY_LOCAL_MACHINE);
if (bRunOnce)
{
if (res && bNormalBoot)
ProcessRunOnceEx(HKEY_LOCAL_MACHINE);
if (res && (SHRestricted(REST_NOLOCALMACHINERUNONCE) == 0))
res = ProcessRunKeys(HKEY_LOCAL_MACHINE, L"RunOnce", TRUE, TRUE);
if (res && (SHRestricted(REST_NOLOCALMACHINERUNONCE) == 0))
res = ProcessRunKeys(HKEY_LOCAL_MACHINE, L"RunOnce", TRUE, TRUE);
return !res;
}
if (res && bNormalBoot && (SHRestricted(REST_NOLOCALMACHINERUN) == 0))
res = ProcessRunKeys(HKEY_LOCAL_MACHINE, L"Run", FALSE, FALSE);
@ -505,7 +510,7 @@ INT ProcessStartupItems(VOID)
return res ? 0 : 101;
}
BOOL DoFinishStartupItems(VOID)
VOID ReleaseStartupMutex()
{
if (s_hStartupMutex)
{
@ -513,13 +518,10 @@ BOOL DoFinishStartupItems(VOID)
CloseHandle(s_hStartupMutex);
s_hStartupMutex = NULL;
}
return TRUE;
}
BOOL DoStartStartupItems(ITrayWindow *Tray)
static BOOL InitializeStartupMutex()
{
DWORD dwWait;
if (!bExplorerIsShell)
return FALSE;
@ -532,15 +534,22 @@ BOOL DoStartStartupItems(ITrayWindow *Tray)
return FALSE;
}
dwWait = WaitForSingleObject(s_hStartupMutex, INFINITE);
DWORD dwWait = WaitForSingleObject(s_hStartupMutex, INFINITE);
TRACE("dwWait: 0x%08lX\n", dwWait);
if (dwWait != WAIT_OBJECT_0)
{
TRACE("LastError: %ld\n", GetLastError());
DoFinishStartupItems();
ReleaseStartupMutex();
return FALSE;
}
return TRUE;
}
BOOL DoStartStartupItems(ITrayWindow *Tray)
{
if (!bExplorerIsShell || !InitializeStartupMutex())
return FALSE;
const DWORD dwWaitTotal = 3000; // in milliseconds
DWORD dwTick = GetTickCount();
@ -575,3 +584,9 @@ BOOL DoStartStartupItems(ITrayWindow *Tray)
return TRUE;
}
VOID ProcessRunOnceItems()
{
if (bExplorerIsShell && IsUserAnAdmin() && InitializeStartupMutex())
ProcessStartupItems(TRUE);
}