Skip to content

Commit fcab0fc

Browse files
authored
Merge pull request #29 from xisheng/master
change for non-default WS installation diretory
2 parents 10de22f + 12adbd2 commit fcab0fc

1 file changed

Lines changed: 29 additions & 25 deletions

File tree

pkg/drivers/vmware/vmware_windows.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,11 @@ limitations under the License.
1717
package vmware
1818

1919
import (
20-
"path/filepath"
21-
"strings"
22-
20+
"fmt"
2321
"golang.org/x/sys/windows/registry"
22+
"path/filepath"
2423
)
2524

26-
var windowsInstallDir = `C:\Program Files (x86)\VMware\VMware Workstation`
27-
28-
func init() {
29-
// Parse HKEY_.CLASSES_ROOT\vm\shell\open\command's value like:
30-
// "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" "%1"
31-
// in order to the Workstation install dir.
32-
key, err := registry.OpenKey(registry.CLASSES_ROOT, `vm\shell\open\command`, registry.QUERY_VALUE)
33-
if err != nil {
34-
return
35-
}
36-
defer key.Close()
37-
38-
value, _, err := key.GetStringValue("")
39-
if err != nil {
40-
return
41-
}
42-
43-
if value[0] == '"' {
44-
values := strings.Split(value[1:], "\"")
45-
windowsInstallDir = filepath.Dir(values[0])
46-
}
47-
}
4825

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

6037
func setVmwareCmd(cmd string) string {
6138
cmd = cmd + ".exe"
39+
DefaultVMWareWSProductionRegistryKey := `SOFTWARE\WOW6432Node\VMware, Inc.`
40+
DefaultVMwareCorePathKey := "Core"
41+
k, err := registry.OpenKey(registry.LOCAL_MACHINE, DefaultVMWareWSProductionRegistryKey, registry.QUERY_VALUE)
42+
if err != nil {
43+
return ""
44+
}
45+
defer k.Close()
46+
production, _, err := k.GetStringValue(DefaultVMwareCorePathKey)
47+
if err != nil {
48+
return ""
49+
}
50+
51+
//Get the VMware Product Install Path
52+
DefaultVMwareWSRegistryKey := fmt.Sprintf(`SOFTWARE\WOW6432Node\VMware, Inc.\%s`, production)
53+
DefaultVMwareWSInstallPathKey := "InstallPath"
54+
55+
key, err := registry.OpenKey(registry.LOCAL_MACHINE, DefaultVMwareWSRegistryKey, registry.QUERY_VALUE)
56+
if err != nil {
57+
return ""
58+
}
59+
defer key.Close()
60+
61+
value, _, err := key.GetStringValue(DefaultVMwareWSInstallPathKey)
62+
if err != nil {
63+
return ""
64+
}
65+
windowsInstallDir := value
6266
return filepath.Join(windowsInstallDir, cmd)
6367
}
6468

0 commit comments

Comments
 (0)