Executing application from users AppData

I have an application which runs in system context but after installation completes i need to start an executable which resides in the users appdata.
My command so far is:

Execute-Process -FilePath "$envUserProfile\AppData\App\App.exe"

But looking at the log it tries to launch it as:

C:\Windows\System32\Config\SystemProfile\AppData\App\App.exe

The path above is normal i guess for system context but i would think using $envUserProfile it should translate into the users profile. Is there any other way to do this? Ive tried Execute-ProcessAsUser but that just starts the program in user context, it still doesnt translate into the AppData path.

If you need to run it from the current user’s folder than this should work.
Unless we are talking about a machine where multiple users are allowed to log in at once.
There you would have to run a loop.

$CurrentUserName = $RunAsActiveUser.UserName
if ($CurrentUserName)
{
    $PathToExecute = "$envSystemDrive\Users\$CurrentUserName\AppData\Roaming"
    Execute-Process -Path "$PathToExecute\App\App.exe"
}
1 Like

Thanks that worked! :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.