windows: use proper system directory path in fallback loader
The %WINDIR% variable is an odd choice and not even entirely reliable.
Since Windows 2000, there has been a specific function for determining
this information, so let's use it. It's also a useful function in its
own right for folks who want to launch system tools in a somewhat safe
way, like netsh.exe.
Updates golang/go#14959
Updates golang/go#30642
Change-Id: Ic24baf37d14f2daced0c1db2771b5a673d2c8852
Reviewed-on: https://go-review.googlesource.com/c/sys/+/165759
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
diff --git a/windows/dll_windows.go b/windows/dll_windows.go
index e92c05b..ba67658 100644
--- a/windows/dll_windows.go
+++ b/windows/dll_windows.go
@@ -359,11 +359,11 @@
// trying to load "foo.dll" out of the system
// folder, but LoadLibraryEx doesn't support
// that yet on their system, so emulate it.
- windir, _ := Getenv("WINDIR") // old var; apparently works on XP
- if windir == "" {
- return nil, errString("%WINDIR% not defined")
+ systemdir, err := GetSystemDirectory()
+ if err != nil {
+ return nil, err
}
- loadDLL = windir + "\\System32\\" + name
+ loadDLL = systemdir + "\\" + name
}
}
h, err := LoadLibraryEx(loadDLL, 0, flags)