1

According to Task Scheduler- Batch "Run whether user is logged on or not" not working and other articles, "Run whether user is logged on or not" requires pure batch processing without interactive and UI.

How to run a wsl2 program on system start? I have tried use wsl -e ... and wsl --shell-type none

  • I'm having trouble understanding your question. Do you require user interaction? Or don't you, but somehow it doesn't work? And if the latter, what is the error message? – LPChip Mar 01 '24 at 08:37
  • @LPChip I'm sorry if I made it confusing. I don't need interaction, I just want to run the batch before user login. There is no error message, the only hint is that when manually run the task, Task Scheduler immediately reports the batch exit with code 1. – BrandonStudio Mar 03 '24 at 10:25

1 Answers1

0

This problem is the subject of bug-report Unable to start WSL via Task Scheduler #8835 from Sep 19, 2022, and running up to almost today.

There are several listed workarounds for the problem that you could try. The one that worked for more than one user was to use a non-Store distribution - the Store versions seem unable to start with "Run whether user is logged on or not".

There are other solutions, some using PsExec, that you may find in this bug-report.

harrymc
  • 480,290
  • The reason why I must run it as a user rather than system is because the whole WSL image is inside the user. As a result all programs inside that WSL image can only be executed in context of that user. Could you please tell me whether I am right about this? – BrandonStudio Mar 03 '24 at 10:29
  • Do the WSL programs work only on WSL files, or also on Windows files outside of WSL? – harrymc Mar 03 '24 at 11:04
  • For me I work only on WSL files, but I would also like to know the difference – BrandonStudio Mar 03 '24 at 11:18
  • In such a case, the WSL user account has no relation to the Windows account. A standard Windows user may login as root to the WSL distribution. – harrymc Mar 03 '24 at 11:20
  • Well, actually, the WSL distribution is installed user-wide, and the whole Linux system disk (ext4.vhdx) is in user's %LocalAppData%. In fact if another user type wsl in terminal, an error message will show up, saying there is no installed distribution for WSL. – BrandonStudio Mar 11 '24 at 05:56
  • That's another problem. See link. – harrymc Mar 11 '24 at 08:11