github.com/google/cadvisor@v0.49.1/machine/operatingsystem_windows.go (about) 1 // Copyright 2020 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package machine 16 17 import ( 18 "fmt" 19 20 "golang.org/x/sys/windows/registry" 21 ) 22 23 func getOperatingSystem() (string, error) { 24 system := "Windows" 25 k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) 26 if err != nil { 27 return system, err 28 } 29 defer k.Close() 30 31 productName, _, err := k.GetStringValue("ProductName") 32 if err != nil { 33 return system, nil 34 } 35 36 releaseId, _, err := k.GetStringValue("ReleaseId") 37 if err != nil { 38 return system, err 39 } 40 41 currentBuildNumber, _, err := k.GetStringValue("CurrentBuildNumber") 42 if err != nil { 43 return system, err 44 } 45 revision, _, err := k.GetIntegerValue("UBR") 46 if err != nil { 47 return system, err 48 } 49 50 system = fmt.Sprintf("%s Version %s (OS Build %s.%d)", 51 productName, releaseId, currentBuildNumber, revision) 52 53 return system, nil 54 }