API through Visual Basic Script (VB Script) -- outdated sample
Posted: 21. Jan 2022, 05:04
I'm looking through the SDK to find samples for using the API through MSCOM by using VBscript. The sample code is provided at... sdk\bindings\mscom\vbs\sample\vboxinfo.vbs -- However, the code is outdated as it was still using openRemoteSession(uuidMachine, ...) which was obsolete at API version 4.0.
So, naturally, I have to make one up on a whim. So far, I got this for launching a VM...
Unfortunately, when I was running the script through CSCRIPT on Windows Command Prompt, a runtime error happens once it got to "launch vm process". I had also tried running it as administrator. Here's the output when running the VBscript...
Perhaps I'm too naïve with VBscript, but I couldn't figure out what I'm doing wrong. I couldn't find any solutions online on launching a virtual machine by using VBscript. Perhaps I can use Python, but I wanted to find out -- just to save me some work, is if the API still works with VBscript. Because, ultimately, the sample source code provided in the SDK is too old.
Here are my specs...
OS: Windows 10 (64-bit) Home 21H1 19043.1466
VirtualBox Version: 6.1.30 (as shown by running script)
API Version: 6.1 (as shown by running script)
CSCRIPT version: 5.812
So, naturally, I have to make one up on a whim. So far, I got this for launching a VM...
Code: Select all
' vmtest.vbs -- VBScript test -- launch a vm
Dim vb
Set vb = CreateObject("VirtualBox.VirtualBox")
Wscript.Echo "VirtualBox version: " & vb.version
Wscript.Echo "package: " & vb.packageType
Wscript.Echo "API version: " & vb.APIVersion
Dim mch
Set mch = vb.FindMachine("new_wXP")
Wscript.Echo "Machine: " & mch.name
Dim ses
Set ses = CreateObject("VirtualBox.Session")
Dim prog
' this is where it throws a "type mismatch" exception...
Set prog = mch.launchVMProcess(ses,"gui","")
' haven't got this far...
prog.waitForCompletion(-1)
session.close()
Code: Select all
D:\virtualbox\scripts>cscript vmtest.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
VirtualBox version: 6.1.30
package: WINDOWS_64BITS_GENERIC
API version: 6_1
Machine: new_wXP
D:\virtualbox\scripts\vmtest.vbs(23, 1) Microsoft VBScript runtime error: Type mismatch: 'launchVMProcess'
D:\virtualbox\scripts>
Here are my specs...
OS: Windows 10 (64-bit) Home 21H1 19043.1466
VirtualBox Version: 6.1.30 (as shown by running script)
API Version: 6.1 (as shown by running script)
CSCRIPT version: 5.812