Skip to content

Commit

Permalink
Merge pull request #29 from xisheng/master
Browse files Browse the repository at this point in the history
change for non-default WS installation diretory
  • Loading branch information
mikeroySoft committed May 12, 2021
2 parents 10de22f + 12adbd2 commit fcab0fc
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions pkg/drivers/vmware/vmware_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,11 @@ limitations under the License.
package vmware

import (
"path/filepath"
"strings"

"fmt"
"golang.org/x/sys/windows/registry"
"path/filepath"
)

var windowsInstallDir = `C:\Program Files (x86)\VMware\VMware Workstation`

func init() {
// Parse HKEY_.CLASSES_ROOT\vm\shell\open\command's value like:
// "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" "%1"
// in order to the Workstation install dir.
key, err := registry.OpenKey(registry.CLASSES_ROOT, `vm\shell\open\command`, registry.QUERY_VALUE)
if err != nil {
return
}
defer key.Close()

value, _, err := key.GetStringValue("")
if err != nil {
return
}

if value[0] == '"' {
values := strings.Split(value[1:], "\"")
windowsInstallDir = filepath.Dir(values[0])
}
}

func DhcpConfigFiles() string {
return `C:\ProgramData\VMware\vmnetdhcp.conf`
Expand All @@ -59,6 +36,33 @@ func SetUmask() {

func setVmwareCmd(cmd string) string {
cmd = cmd + ".exe"
DefaultVMWareWSProductionRegistryKey := `SOFTWARE\WOW6432Node\VMware, Inc.`
DefaultVMwareCorePathKey := "Core"
k, err := registry.OpenKey(registry.LOCAL_MACHINE, DefaultVMWareWSProductionRegistryKey, registry.QUERY_VALUE)
if err != nil {
return ""
}
defer k.Close()
production, _, err := k.GetStringValue(DefaultVMwareCorePathKey)
if err != nil {
return ""
}

//Get the VMware Product Install Path
DefaultVMwareWSRegistryKey := fmt.Sprintf(`SOFTWARE\WOW6432Node\VMware, Inc.\%s`, production)
DefaultVMwareWSInstallPathKey := "InstallPath"

key, err := registry.OpenKey(registry.LOCAL_MACHINE, DefaultVMwareWSRegistryKey, registry.QUERY_VALUE)
if err != nil {
return ""
}
defer key.Close()

value, _, err := key.GetStringValue(DefaultVMwareWSInstallPathKey)
if err != nil {
return ""
}
windowsInstallDir := value
return filepath.Join(windowsInstallDir, cmd)
}

Expand Down

0 comments on commit fcab0fc

Please sign in to comment.