Forum Discussion

szilardd's avatar
szilardd
Brass Contributor
Apr 26, 2023
Solved

MSIX app execution alias from cannot be selected from Task Scheduler

I have a WinForms app packaged with MSIX. One of the requirements is to be able to run the app in background mode from Windows Task Scheduler by passing a specific command line argument.

 

Because MSIX apps can't be executed from their installation folder, the solution was to create an AppExecutionAlias as described here:

 

https://learn.microsoft.com/en-us/windows/msix/psf/create-shortcut-with-script-package-support-framework#create-the-application-alias

 

This was working properly for a while but now it doesn't anymore. When I try to select the app alias from %localappdata%\AppData\Local\Microsoft\WindowsApps, I get the error message

 

'The file cannot be accessed by the system' (see attached screenshot for details)

 

The same error is shown when trying to select another app, like `python` or `Skype`.

 

If I start the app alias from Windows Explorer or from the command line, it works. It doesn't work from Task Scheduler only.

 

Is there any way to work around this issue? It was definitely working before, is there maybe a setting that controls this that was added by a recent windows update?

 

Thanks

  • Found a workaround. Instead of configuring the task to execute the app directly like this:

    %localappdata%\AppData\Local\Microsoft\WindowsApps\MyAppName.Exe

    It can be 'proxied' through cmd.exe. And the task needs to be configured as 'Run only when user is logged on':

    cmd /C "%localappdata%\AppData\Local\Microsoft\WindowsApps\MyAppName.Exe" Arg1

    The problem with this is that it always opened the cmd window while running so it wasn't exactly running in the background. After trying several solution, the one that worked was to use nircmd (https://www.nirsoft.net/utils/nircmd.html), like this:

    nircmd execmd "%localappdata%\Microsoft\WindowsApps\MyAppName.exe" Arg1

4 Replies

  • szilardd's avatar
    szilardd
    Brass Contributor

    Found a workaround. Instead of configuring the task to execute the app directly like this:

    %localappdata%\AppData\Local\Microsoft\WindowsApps\MyAppName.Exe

    It can be 'proxied' through cmd.exe. And the task needs to be configured as 'Run only when user is logged on':

    cmd /C "%localappdata%\AppData\Local\Microsoft\WindowsApps\MyAppName.Exe" Arg1

    The problem with this is that it always opened the cmd window while running so it wasn't exactly running in the background. After trying several solution, the one that worked was to use nircmd (https://www.nirsoft.net/utils/nircmd.html), like this:

    nircmd execmd "%localappdata%\Microsoft\WindowsApps\MyAppName.exe" Arg1

  • I have not tried what you are doing, but here is my "guess":

    The task scheduler is running as a system process, not as the user. It will "impersonate" the user when necessary, but that isn't the same as being logged in as that user. (for exampe, %localappdata% will point to "C:\ProgramData").

    But the path isn't your big issue, the big issue is that the system account doesn't have that app published to it. PreProvisioned deployment of the app might help, but I am doubting that will be successful. More likely, your trigger needs to run as the user with the app.

    If this helps, please post back results as it will undoubtedly help others too.
    • szilardd's avatar
      szilardd
      Brass Contributor
      This might be the reason why it doesn't allow to select the exe from the UI. But I'm not sure, I also tried with the full path instead of %localappdata%, like this:

      c:\Users\MyUserName\AppData\Local\Microsoft\WindowsApps\MyAppName.exe

      It gives the same error.

      But based on my workaround described in another comment, when running the task it actually does seem to do a 'full impersonation' so %localappdata% points to the proper folder because it's working.
    • szilardd's avatar
      szilardd
      Brass Contributor
      Under security options in Task Scheduler, the task is already configured to run as the user that has the app installed. This doesn't seem to be the underlying issue.

Resources