Skip to content

Commit 6374b2b

Browse files
committed
main: direct users to hotfix URL for KB2921916
Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent fd98538 commit 6374b2b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

main.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"golang.org/x/sys/windows"
18+
"golang.org/x/sys/windows/registry"
1819
"golang.zx2c4.com/wireguard/tun"
1920

2021
"golang.zx2c4.com/wireguard/windows/elevate"
@@ -95,6 +96,47 @@ func checkForAdminDesktop() {
9596
}
9697
}
9798

99+
//TODO: remove me when dropping support for Windows 7
100+
func checkForKB2921916() {
101+
maj, min, _ := windows.RtlGetNtVersionNumbers()
102+
if maj != 6 || min != 1 {
103+
return
104+
}
105+
key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages`, registry.ENUMERATE_SUB_KEYS)
106+
if err != nil {
107+
return
108+
}
109+
defer key.Close()
110+
subkeys, err := key.ReadSubKeyNames(0)
111+
if err != nil {
112+
return
113+
}
114+
found := false
115+
for i := range subkeys {
116+
if strings.Contains(subkeys[i], "KB2921916") {
117+
found = true
118+
break
119+
}
120+
}
121+
if found {
122+
return
123+
}
124+
var url string
125+
const urlTemplate = "https://download.wireguard.com/windows-toolchain/distfiles/Windows6.1-KB2921916-%s.msu"
126+
if runtime.GOARCH == "386" {
127+
url = fmt.Sprintf(urlTemplate, "x86")
128+
} else if runtime.GOARCH == "amd64" {
129+
url = fmt.Sprintf(urlTemplate, "x64")
130+
} else {
131+
return
132+
}
133+
ret, _ := windows.MessageBox(0, windows.StringToUTF16Ptr(l18n.Sprintf("Use of WireGuard on Windows 7 requires KB2921916. Would you like to download the hotfix in your web browser?")), windows.StringToUTF16Ptr(l18n.Sprintf("Missing Windows Hotfix")), windows.MB_ICONWARNING|windows.MB_YESNO)
134+
if ret == 6 {
135+
windows.ShellExecute(0, nil, windows.StringToUTF16Ptr(url), nil, nil, windows.SW_SHOWNORMAL)
136+
}
137+
os.Exit(0)
138+
}
139+
98140
func execElevatedManagerServiceInstaller() error {
99141
path, err := os.Executable()
100142
if err != nil {
@@ -118,6 +160,7 @@ func pipeFromHandleArgument(handleStr string) (*os.File, error) {
118160

119161
func main() {
120162
checkForWow64()
163+
checkForKB2921916()
121164

122165
if len(os.Args) <= 1 {
123166
checkForAdminGroup()

0 commit comments

Comments
 (0)