This blog explains how we can use PowerShell to run an application as the current logged in user.
There are times, for example when deploying an application or a script via SCCM, that the launching process will run as a SYSTEM account but we need to spawn a process in the context of the logged in user instead.
Some people suggest using something like:
But this wont work since it prompts for credentials, and we want this to be automated.
The easiest option is to use a scheduled task. You might want to read our blog on how to create a scheduled task using PowerShell. In this example, we’ll simply try to launch notepad.exe as the logged in user.
If we simply set a scheduled task action of:
The scheduled task will be stuck in a ‘running’ state until we close the notepad.exe process. So instead, we want to “launch and forget” by using cmd.exe with START like so:
There are several other configurations that we need to specify in our final script. For example, we specify that the time it will take to launch our exe will be up to a minute (hopefully much less!), and the scheduled task will auto-delete after this period of time too.
The easiest way to check is to look in the username column of the details tab in task manager for the process you are launching.
It’s an extremely useful example of how we can use PowerShell to run an application as the current logged in user.