Wait for a specific user to authenticate to Windows for the following commands to run

Using SCCM, I created a task scheduled to run once at Windows startup, which has an automatic login with a specific account, and this automatic login will only work once, and at this startup the task that calls it is activated. PSADT ps1 in system context to install some applications. I created two popup alerts in vbs using the parameter “ExecuteProcessAsUser” to run in user context, so the popups are seen by the user, where a popup is executed before any command in psadt, saying something like “Install post osd started , please wait” and another popup that runs at the end of the psadt saying something like “post setup successful”

But when you log in with an account for the first time, the one where Windows is preparing the user profile appears, and only then goes to the desktop, and as the ps1 script is executed when Windows starts, then psadt is already running before going to the desktop, and the first popup is suppressed because the user is not logged in yet, so the popup doesn’t appear but the application installations continue, so I can only see the last popup, which is when the user is already authenticated.

So I wanted to know if it would be possible to make “ExecuteProcessAsUser” run only if user “X” is already authenticated in Windows, making it possible to see this popup.

To target your SpecialUser , in SCCM just assign your SCCM App to that user.

As for your “Popup is too late” problem, you have what they call in the business “a Race Condition”.
You could add an arbitrary delay before the 1st Popup is launched but some computers are slower/faster then others.

I see 2 ways to make your script wait dynamically:

  1. Since the SpecialUser’s profile is not created when the SCCM App is launched, test the CREATION date of your SpecialUser’s Desktop folder to make sure the desktop folder is at least 10 seconds old (for example).

  2. The other way is to test when the desktop is available. I found some C# code that claims to do this here: How to tell if Windows desktop is fully functional (loaded) c# - Stack Overflow
    If you are interested to go this route, I can try to convert it to PowerShell provided you are sure your current PSADT runs elevated as most environments block users from running scripts today.