aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/elastic/gosigar/sys/windows/version.go
blob: d0bca89c141b8de495ad1628ad647d8653e5c6d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// +build windows

package windows

import (
    "fmt"
    "syscall"
)

// Version identifies a Windows version by major, minor, and build number.
type Version struct {
    Major int
    Minor int
    Build int
}

// GetWindowsVersion returns the Windows version information. Applications not
// manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version
// value (6.2).
//
// For a table of version numbers see:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx
func GetWindowsVersion() Version {
    // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
    ver, err := syscall.GetVersion()
    if err != nil {
        // GetVersion should never return an error.
        panic(fmt.Errorf("GetVersion failed: %v", err))
    }

    return Version{
        Major: int(ver & 0xFF),
        Minor: int(ver >> 8 & 0xFF),
        Build: int(ver >> 16),
    }
}

// IsWindowsVistaOrGreater returns true if the Windows version is Vista or
// greater.
func (v Version) IsWindowsVistaOrGreater() bool {
    // Vista is 6.0.
    return v.Major >= 6 && v.Minor >= 0
}