Forum Discussion
szilardd
Apr 26, 2023Brass Contributor
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 ...
- Apr 28, 2023
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
Apr 27, 2023
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.
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
Apr 28, 2023Brass 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.
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.