-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to start WSL via Task Scheduler #8835
Comments
/logs |
Hello! Could you please provide more logs to help us better diagnose your issue? To collect WSL logs, download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:
The scipt will output the path of the log file once done. Once completed please upload the output files to this Github issue. Click here for more info on logging Thank you! |
I have attached two logs. |
I have the same problem. This problem seems to be specific to the Microsoft Store version of wsl. If I uninstall the Microsoft Store WSL app, task schedule can properly start wsl. I tried the vbs trick mentioned here without success. This problem seems to be related to the "Unable to start wsl.exe from a Session 0 prompt which users can run into when trying to start WSL from an ssh session" limitation mentioned in the release blogpost. |
I can confirm, as @cheng-chi said, that this issue is only apparent in the Microsoft Store version of WSL. I am able to start WSL via the Task Scheduler when I use the non-Microsoft Store version. |
And since I'd like to use WSLg, I need the Microsoft Store version... |
+1 |
I think I have found a solution. According to this StackOverflow answer, we can escalate a process out of session 0 using psexec.exe.
|
If the workaround works, it will be very useful until MS can resolve the issue. |
Sadly the workaround didn't work. Even deleted the task & recreated it from scratch using the workaround, no change. |
@brettus78 I have created a GitHub repo for my solution of running wsl at startup. I have also installed the Windows 11 22H2 update so I think it shouldn't be the issue. |
I have the same issue. If I try to use the |
Been flat out - will try the example in the GitHub repo you posted, ASAP. But might be a couple of days before I get a chance. |
Log for October 15, 2022: I just found that it didn't actually work, after shutting down my system when I went to bed and opening it again hours after I woke up. Tried Distrod, but to no avail. I'm ditching WSL 2 for the moment, until they support having one instance usable by all users. |
I can confirm that it works if you run the script with "only when user is logged on" and triggered at log on. |
I need to use "Run whether user is logged in or not" to start wsl2 from taskScheduler. Is this working for anyone? Also can confirm that this is not only related to wsl2 - tried starting notepad.exe and had the same issue |
The only thing I found that worked is to change the user on the task to the group "Users". The downside is that it opens a terminal on the screen. I can't seem to minimize it on execution for some reason. Strange how everyone has a different method that works. |
@GlenC289 solution worked for me on Windows 11. I am copying my Task Scheduler Script. Comments indicate how I setup the Task. Code from the Filename: start-wsl-forward-ports.ps1 follows.
|
@hammadrauf Thanks, I appreciate you taking the time to post your solution. I finally decided to remove the Microsoft Store version (as reported by cheng-chi) above and it has been working normally for me so far. I will keep your post in mind though, just in case MS carries the problem over to the windows version. |
Just ran in the same issue with windows store version trying to start WSL at startup on W10 "whether user is logged in or not". I need to use the Store version to have systemd, but can't manage to make it start automatically :/ My workaround at the moment is launching it manually everytime the machine restarts, which is not ideal. |
|
Yeah that's what I do. But you still need to manually log in at each restart of the machine |
The psexec trick seems to work but not with the -s option. I put pstools into C:\pstools and then in the task scheduler start Program/script: C:\PSTools\psexec64.exe I added a 30 second delay to the task startup and WSL starts without me logging into the system. Edit: I needed to change the startup delay from 30 seconds to 1 minute because only vmcompute.exe did start. vmwp.exe and vmmemWSL had trouble starting. Edit 2: There's a console window appearing on my main account desktop during login. When I logout, WSL running in the other user session is closed so this is not working after all. |
+1 My task scheduler breaks after I run Waiting for Microsoft to solve the issue.. |
I'm unable to start WSL on either Win10 Pro or Win11 Pro through Task Scheduler.
My action for the task is C:\Users\username\Scripts\startwsl.cmd which content is:
C:\Users\username\Scripts\startwsl.vbs content is:
I installed WSL with the command "wsl --install --web-download --no-distribution" and then imported the backup of the VM filesystem with:
I added the Windows feature Windows Subsystem for Linux because the filesystem import wouldn't work without it. I also changed the default username to match the username username defined for the Task Scheduler task. I have systemd running inside WSL VM so it should keep running even though I'm not using it. Could it be that I somehow installed the Microsoft Store version of WSL that is known not to work with the Task Scheduler and session 0? This is baffling as I'm sure I had it working in Win11 Pro already. Edit: Here's the process list that should be running when WSL VM starts up correctly:
|
I don’t think it’s related to the version of WSL at all. If you create a new user, does the task also fail for that user? I’ve observed this issue doesn’t appear when a user is created after the 22H2 upgrade. |
Try if these steps help:
Edit: You might have to add "Log on as a batch job" permissions for the user running the task in: secpol.msc: Security Settings/Local Policies/User Rights Assignment/Log on as a batch job Edit 2: Log on as a batch job
|
I encountered the same issue. It was resolved by
|
Same as cheng-chi, had something similar but fixed it eventually by modifying the user - also be careful about run only when user is logged in. If you choose administrator, make sure that isn't checked off. Also I didn't have much luck running |
The whole point of this ticket is to be able to run WSL2 in session 0, i.e. like a service without a console or GUI. This implies that the task scheduler option Run whether user is logged in or not is checked, as stated in the issue. As a minimal repo, run the following commands in PowerShell: $action = New-ScheduledTaskAction -Execute "C:\Windows\System32\wsl.exe" -Argument "-- touch ~/i-exist-so-i-ran"
Register-ScheduledTask -TaskName "Test WSL session 0" -User "NT AUTHORITY\SYSTEM" -Action $action
Start-ScheduledTask -TaskName "Test WSL session 0" When you then look at the task status, it will indicate failure (error code 1): PS C:\Windows\system32> Get-ScheduledTaskInfo -TaskName "Test WSL session 0"
LastTaskResult : 1 Just confirmed that using the current WSL-Version: 1.2.0.0 |
Try defining the program to start as:
I was able to start it automatically as a Windows service (#8835 (comment)) |
Yes it's running automatically after boot, when started through a Windows service. |
I think you are using an old version of WSL. Can you post your |
@eur2fe I'm using that v1.2.4 that was just released a few days ago. I seem to have skipped one important step in the setup process. You have to install the WSL2 Linux kernel update package for x64 machines from https://aka.ms/wsl2kernel I did the install of wsl_update_x64.msi as the non-admin Windows user that is running the startwsl Windows service. Because I've removed local admin rights from the user running the service, the msi installer asks for the Administrator password. There's still an issue with this kind of setup. If you login to Windows with that non-admin user account, its Ubuntu-20.04 WSL 2 instance will be shut down. You can still use "runas /profile /env /user:accountname cmd.exe" from another account to access it. Now both sshd and tailscaled start automatically on boot in the WSL 2 Ubuntu VM and I can access the VM remotely. |
Hello, any news on this important bug? I tried all the suggested solutions, none worked. This is a core feature, keep us posted |
I also cannot get WSL2 running on system startup, Windows Server 2022 + WSL (1.1.3) + Ubuntu 20.04 LTS I didn't use the Microsoft Store version, afaik, I just did wsl --install in powershell. |
+1 |
/dupe #9231 |
Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report! |
For anyone who ends up finding this as the Google top search hit: There is a fix in the WSL September 2023 update.Steps to solve the issue:
Confirmed working for me on Win10 and WSL 2.0.1. |
Thanks @astuomi. I tried this several times but whenever I manually ran the task like this: The status would change to "Running" but it didn't seem to be doing anything at all. It wasn't until I went back into Properties and used the "Browse" button to pick Copy-and-pasting Actually, Task Scheduler doesn't show the job as finished. My script seems to have finished because I can see the last line has finished executing, but Task Scheduler thinks it's still running. So it's still a bit sketchy but... we'll see if it works. Edit: Seems to be working. |
I'm using Windows Server 2022 where, as test, in Add arguments I typed:
It keeps open due to /k. If I replace it by |
I read through this thread and almost gave up but I watched this tutorial and it just took a quick fix to get wsl command working for my scheduled task: https://www.youtube.com/watch?v=knA6JXOoJkE&ab_channel=BonGuides |
Actually two problems seem to have come together at my side:
My settings are:
With the settings above, WSL starts after boot right before login,
(excerpt)
(excerpt)
( This is an example how it looks after a login into WSL via
The only problem left is, that a logout on Windows closes the ugly window and hence WSL stops. However I think this can be corrected with Task Scheduler if I really need it. |
Not work for me
|
Version
22000.978
WSL Version
Kernel Version
5.15.57.1
Distro Version
Ubuntu 22.04
Other Software
No response
Repro Steps
Create a powershell script with the following:
Create a Task Scheduler task to run the powershell script on boot.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
-ExecutionPolicy Bypass -File C:\Scripts\startwsl.ps1
Restart the machine, or manually run the task.
Expected Behavior
Upon reboot or manually running the task, the WSL instance should start and the ssh daemon should be running. This worked in previous versions of WSL (on Windows 10).
Actual Behavior
Either on reboot or on manually executing the task, WSL does not start.
If I manually run the following command via the command prompt, WSL and the ssh daemon start properly.
In summary, running the same powershell script to launch WSL works from the command prompt but does not work from the task scheduler.
Diagnostic Logs
No response
The text was updated successfully, but these errors were encountered: