diff --git a/README.md b/README.md index 4aaa056..183a1a1 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,13 @@ Windows Password: The program will install a service and start it up. Launch `wsl` then from a `cmd` prompt, run `ping ubuntu1804.wsl`. You can check the Windows hosts file to see what was written. The service will automatically update the IP if the WSL2 VM is stopped and started again. The Windows hosts file is located at: `C:\Windows\System32\drivers\etc\hosts` + +**To remove / uninstall the service:** + +_NOTE: Upgrading Windows Insider will remove the service, but not cleanly. To reinstall after upgrading, first make sure you've downloaded the latest version of `wsl2host`, then run `remove` before `install`_ + +Open an **elevated/administrator** command prompt: + +``` +> .\wsl2host.exe remove +``` diff --git a/cmd/wsl2host/internal/install.go b/cmd/wsl2host/internal/install.go index 70e4b1d..a7e2837 100644 --- a/cmd/wsl2host/internal/install.go +++ b/cmd/wsl2host/internal/install.go @@ -84,6 +84,7 @@ func InstallService(name, desc string) error { // RemoveService uninstalls the Windows service func RemoveService(name string) error { + var err2 error m, err := mgr.Connect() if err != nil { return err @@ -91,16 +92,20 @@ func RemoveService(name string) error { defer m.Disconnect() s, err := m.OpenService(name) if err != nil { - return fmt.Errorf("service %s is not installed", name) - } - defer s.Close() - err = s.Delete() - if err != nil { - return err + err2 = fmt.Errorf("service %s is not installed", name) + } else { + defer s.Close() + err = s.Delete() + if err != nil { + err2 = fmt.Errorf("%w; %s", err2, err.Error()) + } } err = eventlog.Remove(name) if err != nil { - return fmt.Errorf("RemoveEventLogSource() failed: %s", err) + err2 = fmt.Errorf("%w; RemoveEventLogSource() failed: %s", err2, err) + } + if err2 != nil { + return err2 } return nil }