HRESULT
RunScriptInGuest([in] BSTR interrpeter,
[in] BSTR scriptText,
[in] LONG options,
[in] IVixHandle* propertyList,
[in] ICallback* jobDoneCallback,
[out,retval] IJob** runJob);
This function runs a script in the guest operating system.
Dim lib
Dim host
Dim job
Dim vm
Dim result
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)
' 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(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
End If
Set host = results(0)
Set job = host.OpenVM("c:\Virtual Machines\vm1\win2000.vmx", Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
End If
Set vm = results(0)
Set job = vm.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI, Nothing, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
End If
Set job = vm.WaitForToolsInGuest(300, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
End If
Set job = vm.LoginInGuest("vixuser", "secret", 0, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
End If
Dim scriptText
scriptText = "if (!open IN, "<", "in.txt") { die "failed to open input file"};\n"
scriptText = scriptText & "if (!open OUT, ">", "out.txt") { die "failed to open output file"};\n"
scriptText = scriptText & "@input = <IN>;\n"
scriptText = scriptText & "@reverse = reverse @input;\n"
scriptText = scriptText & "print OUT @reverse;\n"
Set job = vm.RunScriptInGuest("c:\perl\perl.exe", scriptText, 0, Nothing, Nothing)
err = job.WaitWithoutResults()
If lib.ErrorIndicatesFailure(err) Then
' Handle the error...
End If
host.Disconnect()