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.
19 homeKey = "USERPROFILE"
24 var installPath = `c:\go`
26 func isWindowsXP() bool {
27 v, err := syscall.GetVersion()
29 log.Fatalf("GetVersion failed: %v", err)
35 func whichGo(ctx context.Context) (string, error) {
36 return findGo(ctx, "where")
39 // currentShell reports the current shell.
40 // It might be "powershell.exe", "cmd.exe" or any of the *nix shells.
42 // Returns empty string if the shell is unknown.
43 func currentShell() string {
44 shell := os.Getenv("SHELL")
50 pe, err := getProcessEntry(pid)
52 verbosef("getting shell from process entry failed: %v", err)
56 return syscall.UTF16ToString(pe.ExeFile[:])
59 func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) {
60 // From https://go.googlesource.com/go/+/go1.8.3/src/syscall/syscall_windows.go#941
61 snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0)
65 defer syscall.CloseHandle(snapshot)
67 var procEntry syscall.ProcessEntry32
68 procEntry.Size = uint32(unsafe.Sizeof(procEntry))
69 if err = syscall.Process32First(snapshot, &procEntry); err != nil {
74 if procEntry.ProcessID == uint32(pid) {
75 return &procEntry, nil
78 if err := syscall.Process32Next(snapshot, &procEntry); err != nil {
84 func persistEnvChangesForSession() error {