github.com/shiroyuki/docker@v1.9.0/pkg/parsers/operatingsystem/operatingsystem_windows.go (about) 1 package operatingsystem 2 3 import ( 4 "syscall" 5 "unsafe" 6 ) 7 8 // See https://code.google.com/p/go/source/browse/src/pkg/mime/type_windows.go?r=d14520ac25bf6940785aabb71f5be453a286f58c 9 // for a similar sample 10 11 // GetOperatingSystem gets the name of the current operating system. 12 func GetOperatingSystem() (string, error) { 13 14 var h syscall.Handle 15 16 // Default return value 17 ret := "Unknown Operating System" 18 19 if err := syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, 20 syscall.StringToUTF16Ptr(`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\`), 21 0, 22 syscall.KEY_READ, 23 &h); err != nil { 24 return ret, err 25 } 26 defer syscall.RegCloseKey(h) 27 28 var buf [1 << 10]uint16 29 var typ uint32 30 n := uint32(len(buf) * 2) // api expects array of bytes, not uint16 31 32 if err := syscall.RegQueryValueEx(h, 33 syscall.StringToUTF16Ptr("ProductName"), 34 nil, 35 &typ, 36 (*byte)(unsafe.Pointer(&buf[0])), 37 &n); err != nil { 38 return ret, err 39 } 40 ret = syscall.UTF16ToString(buf[:]) 41 42 return ret, nil 43 } 44 45 // IsContainerized returns true if we are running inside a container. 46 // No-op on Windows, always returns false. 47 func IsContainerized() (bool, error) { 48 return false, nil 49 }