shayne / go-wsl2-host

Automatically update your Windows hosts file with the WSL2 VM IP address
1.65k stars 142 forks source link

wsl2host service error:failed to get infos: wsl list all failed: wsl -l -v failed: exit status 1 #77

Open yanhaiqin518 opened 2 years ago

yanhaiqin518 commented 2 years ago

Windows Log -> Application: failed to get infos: wsl list all failed: wsl -l -v failed: exit status 1

yanhaiqin518 commented 2 years ago

through powershell excute this command is no problem: PS C:\WINDOWS\system32> wsl -l -v NAME STATE VERSION

iamqiz commented 1 year ago

我也是这个问题,我写了个bash script来自动更新,试试? see: iamqiz/bash-wsl2-host: bash script to Automatically update your Windows hosts file with the WSL2 VM IP address https://github.com/iamqiz/bash-wsl2-host

bayard commented 1 year ago

Wsl2host is broken in latest update of windows 11 (Only work in debug mode, service mode result in wsl -l -v error and cannot obtain ip address of wsl.). I wrote a script in linux to complete the job, see: https://github.com/bayard/WSL2_UPDATE_HOSTS

berndgz commented 1 year ago

see: berndgz/wsl2hosts: Bash script to automatically update your Windows hosts file with the WSL2 VM IP address and name. https://github.com/berndgz/wsl2hosts

rufik commented 1 year ago

Same here :/ Right now I'm able to make it working by calling wsl2host.exe run right after WSL start. Latest development version is needed: https://github.com/shayne/go-wsl2-host/releases/tag/latest

eggbean commented 1 year ago

I wanted to automate the running of wslhost.exe run, so I made a powershell script which is run by ~/.zshenv or ~/.bash_profile (so not that often) which makes a Windows Event Log. Then made a Scheduled Task which runs wslhost.exe run when that event occurs.

Everything works fine, but a terminal window opens up briefly while wsl2hosts runs, which is annoying. I can't hide it by running as the SYSTEM account as it doesn't work ☹️

bayard commented 1 year ago

The systemctl script run upon network interface changes after ip address change. Bash profile only triggers only after you login via ssh/telnet. So systemctl is the best choice.

eggbean commented 1 year ago

@bayard Yes, using a systemd service is a much better idea, but I still cannot use cmdow to hide the go-wsl2-host window without run being the default action, as it won't take arguments.

It does seem to do it by default when double-clicking the executable, so if anybody could fix that, that would be cool.

@bayard I am using your solution now, which works nicely. The only small downside is having to make the hosts file user writable. I have made a PR for a couple of minor changes. Cheers.