2015-05-08 17:59:38 -04:00
|
|
|
package operatingsystem
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// See https://code.google.com/p/go/source/browse/src/pkg/mime/type_windows.go?r=d14520ac25bf6940785aabb71f5be453a286f58c
|
|
|
|
// for a similar sample
|
|
|
|
|
2015-07-25 04:35:07 -04:00
|
|
|
// GetOperatingSystem gets the name of the current operating system.
|
2015-05-08 17:59:38 -04:00
|
|
|
func GetOperatingSystem() (string, error) {
|
|
|
|
|
|
|
|
var h syscall.Handle
|
|
|
|
|
|
|
|
// Default return value
|
|
|
|
ret := "Unknown Operating System"
|
|
|
|
|
|
|
|
if err := syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE,
|
|
|
|
syscall.StringToUTF16Ptr(`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\`),
|
|
|
|
0,
|
|
|
|
syscall.KEY_READ,
|
|
|
|
&h); err != nil {
|
|
|
|
return ret, err
|
|
|
|
}
|
|
|
|
defer syscall.RegCloseKey(h)
|
|
|
|
|
|
|
|
var buf [1 << 10]uint16
|
|
|
|
var typ uint32
|
|
|
|
n := uint32(len(buf) * 2) // api expects array of bytes, not uint16
|
|
|
|
|
|
|
|
if err := syscall.RegQueryValueEx(h,
|
|
|
|
syscall.StringToUTF16Ptr("ProductName"),
|
|
|
|
nil,
|
|
|
|
&typ,
|
|
|
|
(*byte)(unsafe.Pointer(&buf[0])),
|
|
|
|
&n); err != nil {
|
|
|
|
return ret, err
|
|
|
|
}
|
|
|
|
ret = syscall.UTF16ToString(buf[:])
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2015-07-25 04:35:07 -04:00
|
|
|
// IsContainerized returns true if we are running inside a container.
|
|
|
|
// No-op on Windows, always returns false.
|
2015-05-08 17:59:38 -04:00
|
|
|
func IsContainerized() (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
}
|