1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
20 homeKey = "USERPROFILE"
25 var installPath = `c:\go`
27 func isWindowsXP() bool {
28 v, err := syscall.GetVersion()
30 log.Fatalf("GetVersion failed: %v", err)
36 func whichGo(ctx context.Context) (string, error) {
37 return findGo(ctx, "where")
40 // currentShell reports the current shell.
41 // It might be "powershell.exe", "cmd.exe" or any of the *nix shells.
43 // Returns empty string if the shell is unknown.
44 func currentShell() string {
45 shell := os.Getenv("SHELL")
51 pe, err := getProcessEntry(pid)
53 verbosef("getting shell from process entry failed: %v", err)
57 return syscall.UTF16ToString(pe.ExeFile[:])
60 func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) {
61 // From https://go.googlesource.com/go/+/go1.8.3/src/syscall/syscall_windows.go#941
62 snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0)
66 defer syscall.CloseHandle(snapshot)
68 var procEntry syscall.ProcessEntry32
69 procEntry.Size = uint32(unsafe.Sizeof(procEntry))
70 if err = syscall.Process32First(snapshot, &procEntry); err != nil {
75 if procEntry.ProcessID == uint32(pid) {
76 return &procEntry, nil
79 if err := syscall.Process32Next(snapshot, &procEntry); err != nil {
85 func persistEnvChangesForSession() error {