From eb786cd7c11335708133624eda678dfad54048d6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 19 Aug 2019 09:20:23 +0200 Subject: wintun: also set friendly name after setting interface name --- tun/wintun/wintun_windows.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go index 2f8fcc1..4bf17e6 100644 --- a/tun/wintun/wintun_windows.go +++ b/tun/wintun/wintun_windows.go @@ -563,19 +563,34 @@ func (wintun *Wintun) InterfaceName() (string, error) { // SetInterfaceName sets name of the Wintun interface. func (wintun *Wintun) SetInterfaceName(ifname string) error { + netRegKey, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.netRegKeyName(), registry.SET_VALUE) + if err != nil { + return fmt.Errorf("Network-specific registry key open failed: %v", err) + } + defer netRegKey.Close() + err = netRegKey.SetStringValue("Name", ifname) + if err != nil { + return err + } + deviceRegKey, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.deviceRegKeyName(), registry.SET_VALUE) + if err != nil { + return fmt.Errorf("Device-level registry key open failed: %v", err) + } + defer deviceRegKey.Close() + err = deviceRegKey.SetStringValue("DeviceDesc", deviceTypeName) + if err != nil { + return err + } + err = deviceRegKey.SetStringValue("FriendlyName", deviceTypeName) + if err != nil { + return err + } // We have to tell the various runtime COM services about the new name too. We ignore the // error because netshell isn't available on servercore. // TODO: netsh.exe falls back to NciSetConnection in this case. If somebody complains, maybe // we should do the same. netshell.HrRenameConnection(&wintun.cfgInstanceID, windows.StringToUTF16Ptr(ifname)) - - // Set the interface name. The above line should have done this too, but in case it failed, we force it. - key, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.netRegKeyName(), registry.SET_VALUE) - if err != nil { - return fmt.Errorf("Network-specific registry key open failed: %v", err) - } - defer key.Close() - return key.SetStringValue("Name", ifname) + return nil } // netRegKeyName returns the interface-specific network registry key name. -- cgit v1.2.3