Use for $RunAsActiveUser

I have a script that checks for a running process before running an install. If the process is running but logonui is running the install will run. If the process is running but logonui is not running, the script will exit. This is working just fine.

In the Post-install area, I’d like to start the application that was just installed/upgraded (hence the need to check if it is running and machine is locked) but it needs to start as the currently logged on user without prompting for a password. I tested the following:

Start-Process powershell.exe -Credential $RunAsActiveUser

But I was met with a credential prompt.

I don’t think Execute-ProcessAsUser will work as that creates a scheduled task and I just need to start the application as the currently logged on user.

Look at PSADT’s $CurrentLoggedOnUserSession array, specifically $CurrentLoggedOnUserSession.IsUserSession

I think this is what you need.