2013-07-27 16:00:21 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package vmware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2013-07-27 17:59:23 -04:00
|
|
|
"syscall"
|
2013-07-27 16:00:21 -04:00
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
func workstationCheckLicense() error {
|
|
|
|
// Not implemented on Windows
|
2013-07-27 16:00:21 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
func workstationFindVdiskManager() (string, error) {
|
|
|
|
path, err := exec.LookPath("vmware-vdiskmanager.exe")
|
|
|
|
if err == nil {
|
|
|
|
return path, nil
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
path, err = workstationVMwareRoot()
|
2013-07-27 16:00:21 -04:00
|
|
|
if err != nil {
|
2013-07-31 15:36:17 -04:00
|
|
|
return "", err
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
return filepath.Join(path, "vmware-vdiskmanager.exe"), nil
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
func workstationFindVMware() (string, error) {
|
|
|
|
path, err := exec.LookPath("vmware.exe")
|
|
|
|
if err == nil {
|
|
|
|
return path, nil
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
path, err = workstationVMwareRoot()
|
2013-07-27 16:00:21 -04:00
|
|
|
if err != nil {
|
2013-07-31 15:36:17 -04:00
|
|
|
return "", err
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
return filepath.Join(path, "vmware.exe"), nil
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
func workstationFindVmrun() (string, error) {
|
|
|
|
path, err := exec.LookPath("vmrun.exe")
|
|
|
|
if err == nil {
|
|
|
|
return path, nil
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
path, err = workstationVMwareRoot()
|
2013-07-27 16:00:21 -04:00
|
|
|
if err != nil {
|
2013-07-31 15:36:17 -04:00
|
|
|
return "", err
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
2013-07-31 15:36:17 -04:00
|
|
|
|
|
|
|
return filepath.Join(path, "vmrun.exe"), nil
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
func workstationToolsIsoPath(flavor string) string {
|
|
|
|
path, err := workstationVMwareRoot()
|
2013-07-27 16:00:21 -04:00
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
2013-07-31 15:36:17 -04:00
|
|
|
|
|
|
|
return filepath.Join(path, flavor+".iso")
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
func workstationDhcpLeasesPath(device string) string {
|
2013-07-27 16:00:21 -04:00
|
|
|
programData := os.Getenv("ProgramData")
|
2013-07-31 15:36:17 -04:00
|
|
|
if programData == "" {
|
2013-07-27 16:00:21 -04:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
return filepath.Join(programData, "/VMware/vmnetdhcp.leases")
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
// See http://blog.natefinch.com/2012/11/go-win-stuff.html
|
|
|
|
//
|
|
|
|
// This is used by workstationVMwareRoot in order to read some registry data.
|
2013-07-27 16:00:21 -04:00
|
|
|
func readRegString(hive syscall.Handle, subKeyPath, valueName string) (value string, err error) {
|
2013-07-27 17:59:23 -04:00
|
|
|
var h syscall.Handle
|
|
|
|
err = syscall.RegOpenKeyEx(hive, syscall.StringToUTF16Ptr(subKeyPath), 0, syscall.KEY_READ, &h)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer syscall.RegCloseKey(h)
|
|
|
|
|
|
|
|
var typ uint32
|
|
|
|
var bufSize uint32
|
|
|
|
err = syscall.RegQueryValueEx(
|
|
|
|
h,
|
|
|
|
syscall.StringToUTF16Ptr(valueName),
|
|
|
|
nil,
|
|
|
|
&typ,
|
|
|
|
nil,
|
|
|
|
&bufSize)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data := make([]uint16, bufSize/2+1)
|
|
|
|
err = syscall.RegQueryValueEx(
|
|
|
|
h,
|
|
|
|
syscall.StringToUTF16Ptr(valueName),
|
|
|
|
nil,
|
|
|
|
&typ,
|
|
|
|
(*byte)(unsafe.Pointer(&data[0])),
|
|
|
|
&bufSize)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return syscall.UTF16ToString(data), nil
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:36:17 -04:00
|
|
|
// This reads the VMware installation path from the Windows registry.
|
|
|
|
func workstationVMwareRoot() (s string, err error) {
|
|
|
|
key := `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vmware.exe`
|
2013-07-27 16:00:21 -04:00
|
|
|
subkey := "Path"
|
2013-07-31 15:36:17 -04:00
|
|
|
s, err = readRegString(syscall.HKEY_LOCAL_MACHINE, key, subkey)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf(`Unable to read registry key %s\%s`, key, subkey)
|
|
|
|
return
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|
2013-07-31 15:36:17 -04:00
|
|
|
|
2013-07-27 16:00:21 -04:00
|
|
|
s = strings.Replace(s, "\\", "/", -1)
|
2013-07-31 15:36:17 -04:00
|
|
|
return
|
2013-07-27 16:00:21 -04:00
|
|
|
}
|