Using Workstation 6, is it possible to start a VM in background mode from the command line? It appears that the VM has to be run with a console first, and then manually put into background mode.
Thanks,
Hugh
Here is a VBScript that will let you start a virtual machine in the background.
(I am not a VBScript guru, so if anyone wants to make this better, please go ahead. This works on my machine, but no promises.).
Just create a new file called "powerOnBackground.vbs" or whatever you chose.
Then copy the following script into the file.
' Do not run this script directly.
' Use the accompanying .wsf script, which will load VixCOM.
' To run the script, type
' cscript //nonlogo powerOnBackground.wsf vmxPath
' where vmxPath is the path the .vmx file for the virtual machine you want
' to power on. You can also put multiple paths, which will power on
' each virtual machine.
Dim lib, job
If Wscript.Arguments.Count = 0 Then
Wscript.Echo("You must specify at least one path to a vmx file.")
Wscript.Quit
End If
Set lib = CreateObject("VixCOM.VixLib")
Set job = lib.Connect(VixCOM.Constants.VIX_API_VERSION, VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION, Empty, 0, Empty, Empty, 0, Nothing, Nothing)
Set results = Nothing
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
QuitIfError(err)
Set host = results(0)
For i = 0 to WScript.Arguments.Count - 1
Set job = host.OpenVM(WScript.Arguments(i), Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
QuitIfError(err)
Set vm = results(0)
Set job = vm.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_NORMAL, Nothing, Nothing)
err = job.WaitWithoutResults()
QuitIfError(err)
Next
host.Disconnect()
'----
' A simple error handler. Prints the error message to the console, and then exits.
sub QuitIfError(err)
if lib.ErrorIndicatesFailure(err) then
WScript.Echo("Error: " & lib.GetErrorText(err, empty))
WScript.Quit
end if
end sub
Then create a second file in the same directory called "powerOnBackground.wsf". Copy the following code into that file:
Make sure that the "src" attribute matches what you named the VBScript file.
Then you can run the script from the command line by typing:
cscript //nologo powerOnBackground.wsf C:\VMs\winxp\winxp.vmx
replacing that path with the path the .vmx file for the virtual machine you want to power on headlessly. This script will also let you supply multiple virtual machines.
Let me know how this works for you and if you have any questions, feel free to ask.
Have you tried using the vmrun command?
Although I can run the VM guest from the command line using either vmrun or the actual vmware executable, the session runs in the foreground. There appears to be no way to start the guest in background mode.
What host OS are you using?
The host OS is XP pro.
Here is a VBScript that will let you start a virtual machine in the background.
(I am not a VBScript guru, so if anyone wants to make this better, please go ahead. This works on my machine, but no promises.).
Just create a new file called "powerOnBackground.vbs" or whatever you chose.
Then copy the following script into the file.
' Do not run this script directly.
' Use the accompanying .wsf script, which will load VixCOM.
' To run the script, type
' cscript //nonlogo powerOnBackground.wsf vmxPath
' where vmxPath is the path the .vmx file for the virtual machine you want
' to power on. You can also put multiple paths, which will power on
' each virtual machine.
Dim lib, job
If Wscript.Arguments.Count = 0 Then
Wscript.Echo("You must specify at least one path to a vmx file.")
Wscript.Quit
End If
Set lib = CreateObject("VixCOM.VixLib")
Set job = lib.Connect(VixCOM.Constants.VIX_API_VERSION, VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION, Empty, 0, Empty, Empty, 0, Nothing, Nothing)
Set results = Nothing
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
QuitIfError(err)
Set host = results(0)
For i = 0 to WScript.Arguments.Count - 1
Set job = host.OpenVM(WScript.Arguments(i), Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
QuitIfError(err)
Set vm = results(0)
Set job = vm.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_NORMAL, Nothing, Nothing)
err = job.WaitWithoutResults()
QuitIfError(err)
Next
host.Disconnect()
'----
' A simple error handler. Prints the error message to the console, and then exits.
sub QuitIfError(err)
if lib.ErrorIndicatesFailure(err) then
WScript.Echo("Error: " & lib.GetErrorText(err, empty))
WScript.Quit
end if
end sub
Then create a second file in the same directory called "powerOnBackground.wsf". Copy the following code into that file:
Make sure that the "src" attribute matches what you named the VBScript file.
Then you can run the script from the command line by typing:
cscript //nologo powerOnBackground.wsf C:\VMs\winxp\winxp.vmx
replacing that path with the path the .vmx file for the virtual machine you want to power on headlessly. This script will also let you supply multiple virtual machines.
Let me know how this works for you and if you have any questions, feel free to ask.
We've also fixed this limitation of vmrun by adding a 'nogui' option to the start command which will allow you to start up a VM in the background with no console. That will be available in the next release. Until then, hopefully the VBScript will get you going...
Sorry for the inconvenience.
Thanks guys. The VBScript works well, and I look forward to this being part of the core product.
Hugh
Seems like Vixcom is a part of some library, which I do not have installed. Can you please clarify VixCom.Vixlib object? Do I need to have something installed?
You would need to have VMware Workstation 6 installed.
What version of Workstation are you using?
Thanks for clarifying, I have v5.5 installed, in process of getting v6
Hi, any workaround for linux hosts until the updated vmrun is available ?
If you are up for some C coding, you can write something very simple with the C VIX API that will do the same thing.
Nice tip thanks
I am using the latest version of VMWare Workstation 6 on XP Pro (6.02 59824). I want to be able to have a Linux server start in the background whenever this PC boots, and I'd actually like to have it possible for the task to restart if its somehow killed. I'm using the server as a SOCKs proxy when I'm behind a firewall in order to use BitTorrent for large file transfers. Anyways, I want this to be entirely transparent for the end users of this PC (mainly my mom and sister) so I would like it just to start the VM in the background without ever opening Workstation.
But if I try a command like this
C:\Program Files\VMware\VMware Workstation>vmrun start C:\Virtual_Machines\Ubunt
u_Server\Ubuntu_Server.vmx nogui
Error: Command failed: The system returned an error. Communication with the virt
ual machine may have been interrupted
But, it will work if I use the gui option (but it starts Workstation in normal mode which I don't want to have happen). What could be causing the issue here with the nogui option? I have tried using the command from both a suspended VM state and a powered off state but both return the same status. Any ideas?
Hi, Have you checked out VMware Server? It may be more akin to what you want to achieve. Don't know if you can have Server and Workstation installed on the same machine though?
I've had the problem where I am using Workstation 6.0.2, I want to start the VM without the GUI.
I issue a command:
vmrun start <path to vmx> nogui
Note that if I leave the "nogui" option off it works fine. When nogui is present, the VM does not start. I get the following error:
Error: Command failed: The system returned an error. Communication with the virtual machine may have been interrupted
When I inspect the log file in C:\Documents and Settings\myname\Local Settings\Temp\vmware-, I see:
-
snip follows
-
Feb 26 17:14:19.020: app| Unable to get information about file "\messages\en\tip_list.vmsg": The system cannot find the path specified.
Feb 26 17:14:19.020: app|
Feb 26 17:14:19.020: app| Cannot load message dictionary "\messages\en\tip_list.vmsg".
Feb 26 17:14:19.099: app| DynaLink oleaut32.dll inaccessible?
Feb 26 17:14:19.099: app|
Feb 26 17:14:19.099: app| Failed to connect to WMI
...
Feb 26 17:14:19.584: app| VMHSVMCbPower: Setting state of VM /vm/#0dc1fc04c10e5301/ to powerOn with option default
Feb 26 17:14:19.584: app| VMHSVMExecVMX: Failed to launch the VMX process: The system cannot find the path specified
Feb 26 17:14:19.599: app| VMHSLaunchVM failed: Failed to launch peer process
-
snip ends
-
Use of Sysinternals FILEMON shows that it is trying to run the vmware-vmx process from c:\bin and it is (obviously) not being found.
There seems to be no registry or other setting to allow the search path for vmware-vmx to be set.
I have tried putting the path to VMware WS into the system PATH, i've tried adding VMWARE_BINDIR as an environment variable, all with no success.
Another giveaway is the error that appears in that log above "Cannot load message dictionary "\messages\en\tip_list.vmsg".
IT LOOKS LIKE SOME KIND OF PATH PREFIX IS MISSING.
I'm running this on Windows XP SP2, and I have the same behaviour on Windows 2000 Server.
I've logged a Support Request with VMWare, but I have no idea when, or if, there will be a reply.
Does anybody have a workaround, or a discovery that can overcome this?
(I can't use VMWare Server because it has no shared files support, so please don't suggest that.)
Someone try to run that script under Vista? It was working fine under Win XP, but on Vista.. "VBScript runtime error: ActiveX component can't create object: 'VixCOM.VixLib'" error massege.
Error related to this point in VBS:
Set lib = CreateObject("VixCOM.VixLib")
Thanks
check if vixcom.dll is registered correctly
regsvr32 %path-tovix%\vixcom.dll
Same problem dll was regsiter correctly.
May be problem is due to my x64 Vista?