Skip to content

Commit

Permalink
Always remove eventlog source when calling emove #7
Browse files Browse the repository at this point in the history
  • Loading branch information
shayne committed Oct 31, 2019
1 parent 57100be commit 9a1681e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ Windows Password: <password-for-this-user>
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
```
19 changes: 12 additions & 7 deletions cmd/wsl2host/internal/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,28 @@ 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
}
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
}

0 comments on commit 9a1681e

Please sign in to comment.