2

Having a hard time with this one. I can run the following command from a command prompt successfully, but can't get it working with a VB script.

From CMD:

  1. Change directory to C:\Program Files (x86)\VMware\VMware Workstation\
  2. then run: vmrun.exe -T ws start "C:\Users\Office\Documents\Virtual Machines\Windows 7\Windows 7.vmx" nogui

What I've tried in VBS:

Dim objShell, strPath1, strAttr, strPath2 
Set objShell = CreateObject ("WScript.Shell")

strPath1 = "C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe"
strAttr1 = " -T ws start "
strAttr2 = "C:\Users\Office\Documents\Virtual Machines\Windows 7\Windows 7.vmx"
strAttr3 = " nogui"

'WScript.Echo strPath1 & strAttr1 & """" & strAttr2 & """" & strAttr3 

objShell.Run strPath1 & strAttr1 & """" & strAttr2 & """" & strAttr3 

The error I get is: The system cannot find the file specified.

4
  • I think you need double double quote every path with spaces Commented Mar 31, 2017 at 1:13
  • Thanks! That was it. It just looked off when viewing the echo output, but it works :) Commented Mar 31, 2017 at 2:14
  • The full code ended up as: Dim objShell, strPath1, strAttr1, strAttr2, strAttr3 Set objShell = CreateObject ("WScript.Shell") strPath1 = """C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe""" strAttr1 = " -T ws start " strAttr2 = """C:\Users\Office\Documents\Virtual Machines\Windows 7\Windows 7.vmx""" strAttr3 = " nogui" 'WScript.Echo strPath1 & strAttr1 & strAttr2 & strAttr3 'objShell.Run strPath1 & strAttr1 & """" & strAttr2 & """" & strAttr3 objShell.Run strPath1 & strAttr1 & strAttr2 & strAttr3 Commented Mar 31, 2017 at 2:16
  • Possible duplicate of Run Command Line & Command From VBS Commented Mar 31, 2017 at 10:28

2 Answers 2

3

Working Code ended up being:

Dim objShell, strPath1, strAttr1, strAttr2, strAttr3
Set objShell = CreateObject ("WScript.Shell")

strPath1 = """C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe"""
strAttr1 = " -T ws start "
strAttr2 = """C:\Users\Office\Documents\Virtual Machines\Windows 7\Windows 7.vmx"""
strAttr3 = " nogui"

objShell.Run strPath1 & strAttr1 & strAttr2 & strAttr3
Sign up to request clarification or add additional context in comments.

Comments

0

i would replace objShell.Run strPath1 & strAttr1 & """" & strAttr2 & """" & strAttr3

with

objShell.Run strPath1 & strAttr1 & chr(34) & strAttr2 & chr(34) & strAttr3

or include the chr(34) before and after the strAttr2 variable

strAttr2 = chr(34) & "C:\Users\Office\Documents\Virtual Machines\Windows 7\Windows 7.vmx" & chr(34)

btw chr(34) = "

1 Comment

or create a variable that already has the quotes to concatenate cleaner var = chr(34) & strAttr2 & chr(34)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.