packer-cn/builder/vmware/common/driver_workstation10_window...

36 lines
971 B
Go
Raw Normal View History

// +build windows
package common
import (
"fmt"
"log"
"regexp"
"syscall"
)
func workstationVerifyVersion(version string) error {
key := `SOFTWARE\Wow6432Node\VMware, Inc.\VMware Workstation`
subkey := "ProductVersion"
productVersion, err := readRegString(syscall.HKEY_LOCAL_MACHINE, key, subkey)
if err != nil {
log.Printf(`Unable to read registry key %s\%s`, key, subkey)
key = `SOFTWARE\VMware, Inc.\VMware Workstation`
productVersion, err = readRegString(syscall.HKEY_LOCAL_MACHINE, key, subkey)
if err != nil {
log.Printf(`Unable to read registry key %s\%s`, key, subkey)
return err
}
}
versionRe := regexp.MustCompile(`^(\d+)\.`)
matches := versionRe.FindStringSubmatch(productVersion)
if matches == nil {
return fmt.Errorf(
"Could not find VMware WS version in registry key %s/subkey: %s", key, subkey, productVersion)
}
log.Printf("Detected VMware WS version: %s", matches[1])
return compareVersions(matches[1], version)
}