i modified the code so that i do not have to change too much for calling with the wsf file.
this is the wsf file content:
<job id="test-wowsf2">
<reference object="VixCOM.VixLib" />
<script language="VBScript" src="test-wowsf2.vbs" />
</job>
this is part of the script that you can see the difference between this and the code at the end
Dim lib
Dim host
Dim vm
Dim err
Dim results
Dim job
dim JOB_RESULT_HANDLE
dim VMPOWEROP_LAUNCH_GUI
dim API_VERSION
dim SERVICEPROVIDER_VMWARE_WORKSTATION
JOB_RESULT_HANDLE =VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE
VMPOWEROP_LAUNCH_GUI=VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI
API_VERSION=VixCOM.Constants.VIX_API_VERSION
SERVICEPROVIDER_VMWARE_WORKSTATION=VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION
WScript.Echo("ApiVersion " & API_VERSION &" JobResultHandle " & JOB_RESULT_HANDLE &" ServiceProviderVMWareWorkstation " & SERVICEPROVIDER_VMWARE_WORKSTATION & " VMPowerOPLaunchGui "& VMPOWEROP_LAUNCH_GUI)
Set lib = CreateObject("VixCOM.VixLib") ' instantiate a COM object
This is the ouput of the console from the working call :
C:\Program Files (x86)\VMware\VMware VIX>c:\windows\SysWOW64\cscript "C:\Program
Files (x86)\VMware\VMware VIX\Samples\test-wowsf2.wsf"
Microsoft (R) Windows Script Host, Version 5.8
Copyright (C) Microsoft Corporation 1996-2001. Alle Rechte vorbehalten.
ApiVersion -1 JobResultHandle 3010 ServiceProviderVMWareWorkstation 3 VMPowerOPL
aunchGui 512
The code below called as vbs results in:
C:\Program Files (x86)\VMware\VMware VIX>c:\windows\SysWOW64\cscript "C:\Program
Files (x86)\VMware\VMware VIX\Samples\test-wowsf3.vbs"
Microsoft (R) Windows Script Host, Version 5.8
Copyright (C) Microsoft Corporation 1996-2001. Alle Rechte vorbehalten.
ApiVersion -1 JobResultHandle 3010 ServiceProviderVMWareWorkstation 3 VMPowerOPL
aunchGui 512
C:\Program Files (x86)\VMware\VMware VIX\Samples\test-wowsf3.vbs(27, 1) Laufzeit
fehler in Microsoft VBScript: Ungültiger Prozeduraufruf oder ungültiges Argument
(sorry i have a german windows ;-) invalid procedure call or invalid argument)
Dim lib
Dim host
Dim vm
Dim err
Dim results
Dim job
dim JOB_RESULT_HANDLE
dim VMPOWEROP_LAUNCH_GUI
dim API_VERSION
dim SERVICEPROVIDER_VMWARE_WORKSTATION
JOB_RESULT_HANDLE =3010
VMPOWEROP_LAUNCH_GUI=512
API_VERSION=-1
SERVICEPROVIDER_VMWARE_WORKSTATION=3
WScript.Echo("ApiVersion " & API_VERSION &" JobResultHandle " & JOB_RESULT_HANDLE &" ServiceProviderVMWareWorkstation " & SERVICEPROVIDER_VMWARE_WORKSTATION & " VMPowerOPLaunchGui "& VMPOWEROP_LAUNCH_GUI)
Set lib = CreateObject("VixCOM.VixLib") ' instantiate a COM object
' use obtained COM object
Set job = lib.Connect(API_VERSION, SERVICEPROVIDER_VMWARE_WORKSTATION, Empty, 0, Empty, Empty, 0, Nothing, Nothing)
' results needs to be initialized before it's used, even if it's just going to be overwritten.
Set results = Nothing
err = job.Wait(Array(JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
QuitIfError(err)
End If
Set host = results(0)
Set job = host.OpenVM("d:\virtual machines\windows server 2003 enterprise edition\windows server 2003 enterprise edition.vmx", Nothing)
err = job.Wait(Array(JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
QuitIfError(err)
End If
Set vm = results(0)
Set job = vm.PowerOn(VMPOWEROP_LAUNCH_GUI, Nothing, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
QuitIfError(err)
End If
'--------------------------------------------------------------------------------
' 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