github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/pkg/parsers/operatingsystem/operatingsystem_windows.go (about)

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