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/syscall_test.go b/windows/syscall_test.go
index d7009e4..f09c6dd 100644
--- a/windows/syscall_test.go
+++ b/windows/syscall_test.go
@@ -7,6 +7,7 @@
package windows_test
import (
+ "strings"
"syscall"
"testing"
@@ -51,3 +52,13 @@
t.Error("shlwapi.dll:IsOS(OS_NT) returned 0, expected non-zero value")
}
}
+
+func TestGetSystemDirectory(t *testing.T) {
+ d, err := windows.GetSystemDirectory()
+ if err != nil {
+ t.Fatalf("Failed to get system directory: %s", err)
+ }
+ if !strings.HasSuffix(strings.ToLower(d), "\\system32") {
+ t.Fatalf("System directory does not end in system32: %s", d)
+ }
+}