Contributions
Re: access VMWare hosts vis VIX API
I found the solution: The problem is, that the datatypes not the same if you are using your own variables The datatype from the constants is LONG so you have to convert your variable. when you run it from wsf file with the vix constants all subtypes of the variables are LONG but in this sample it is only necessary to convert the JOB_RESULT_HANDLE to avoid the error. JOB_RESULT_HANDLE =3010 VMPOWEROP_LAUNCH_GUI=512 API_VERSION=-1 SERVICEPROVIDER_VMWARE_WORKSTATION=3 JOB_RESULT_HANDLE=clng(JOB_RESULT_HANDLE) WScript.Echo("ApiVersion " & API_VERSION &" JobResultHandle " & JOB_RESULT_HANDLE &" ServiceProviderVMWareWorkstation " & SERVICEPROVIDER_VMWARE_WORKSTATION & " VMPowerOPLaunchGui "& VMPOWEROP_LAUNCH_GUI) WScript.Echo("ApiVersion " & vartype(API_VERSION) &" JobResultHandle " & vartype(JOB_RESULT_HANDLE) &" ServiceProviderVMWareWorkstation " & vartype(SERVICEPROVIDER_VMWARE_WORKSTATION) & " VMPowerOPLaunchGui "& vartype(VMPOWEROP_LAUNCH_GUI))2.4KViews0likes0CommentsRe: access VMWare hosts vis VIX API
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 sub2.4KViews0likes0CommentsRe: access VMWare hosts vis VIX API
the problem with vmrun was that the version of my VMWare Workstation was not in the vixwrapper-config.txt included so i had to add it # Workstation 7.0.0 ws 9 vmdb 7.0.0 Workstation-7.0.0 ws 9 vmdb 7.0.1 Workstation-7.0.0 ws 9 vmdb e.x.p Workstation-7.0.0 player 9 vmdb 3.0.0 Workstation-7.0.0 player 9 vmdb e.x.p Workstation-7.0.0 after that vmrun works when i try to run the script with the wsf it works (the constants taken from the vix api) when i try to run the script with the extracted constants i get an runtime error invalid procedure call or invalid argument by the way api_version should be -1 in the script Dim lib Dim host Dim vm Dim err Dim results Dim job Const JOB_RESULT_HANDLE =3010 Const VMPOWEROP_LAUNCH_GUI=512 Const API_VERSION=-1 Const SERVICEPROVIDER_VMWARE_WORKSTATION=3 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 sub2.4KViews0likes0CommentsRe: access VMWare hosts vis VIX API
i tried the script running as vbs and got also this error . i found that this error was a result of an unhandled error. i put the error handling code from the vix example to this script, and get the error "the specified version was not found." so it seems to be a problem with the vix api. when i try to start with vmrun i get the same error. thanks for your help2.4KViews0likes0CommentsRe: access VMWare hosts vis VIX API
Thats the code thats in the wsf file there are no constants in. <job id="powerOn"> <reference object="VixCOM.VixLib" /> <script language="VBScript" src="powerOn1.vbs" /> </job> But i made msgboxes ad get the constants. But now i have the next error in this script. (thats an example you wrote anywhere in the forum) i got the error on line 15 (Set host = results(0) ) types not matching results sub main Dim lib Dim host Dim vm Dim err Dim results Dim job Set lib = CreateObject("VixCOM.VixLib") ' instantiate a COM object ' use obtained COM object Set job = lib.Connect(1, 3, 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(3010), results) If lib.ErrorIndicatesFailure(err) Then ' Handle the error... 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(3010), results) If lib.ErrorIndicatesFailure(err) Then ' Handle the error... End If Set vm = results(0) Set job = vm.PowerOn(512, Nothing, Nothing) err = job.WaitWithoutResults() If lib.ErrorIndicatesFailure(err) Then ' Handle the error... End If end sub2.4KViews0likes0Commentsaccess VMWare hosts vis VIX API
Hello, When i try to access an VMWare guest via the Vix API i get always the error message object required. When i look to the VMWare samples it is necessary to start the script with the .wsf file. But this is not possible in Testcomplete. So how can i access any guest via VIX in Testcomplete? Regards Christian15KViews0likes9Comments