[69257] | 1 | ' $Id: vboxinfo.vbs 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
| 2 | '' @file
|
---|
| 3 | ' ???
|
---|
[21569] | 4 | '
|
---|
[69257] | 5 |
|
---|
| 6 | '
|
---|
[98103] | 7 | ' Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
[21569] | 8 | '
|
---|
[96407] | 9 | ' This file is part of VirtualBox base platform packages, as
|
---|
| 10 | ' available from https://www.virtualbox.org.
|
---|
[21569] | 11 | '
|
---|
[96407] | 12 | ' This program is free software; you can redistribute it and/or
|
---|
| 13 | ' modify it under the terms of the GNU General Public License
|
---|
| 14 | ' as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | ' License.
|
---|
| 16 | '
|
---|
| 17 | ' This program is distributed in the hope that it will be useful, but
|
---|
| 18 | ' WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | ' General Public License for more details.
|
---|
| 21 | '
|
---|
| 22 | ' You should have received a copy of the GNU General Public License
|
---|
| 23 | ' along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | '
|
---|
| 25 | ' SPDX-License-Identifier: GPL-3.0-only
|
---|
| 26 | '
|
---|
[21569] | 27 |
|
---|
| 28 | Sub Print(str)
|
---|
| 29 | Wscript.Echo str
|
---|
[26502] | 30 | End Sub
|
---|
[21569] | 31 |
|
---|
| 32 | Sub StartVm(vb, mach)
|
---|
| 33 | Dim session, progress
|
---|
[26502] | 34 |
|
---|
[21569] | 35 | Set session = CreateObject("VirtualBox.Session")
|
---|
| 36 | Set progress = vb.openRemoteSession(session, mach.id, "gui", "")
|
---|
| 37 | progress.waitForCompletion(-1)
|
---|
| 38 | session.close()
|
---|
| 39 | End Sub
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | Sub StopVm(vb, mach)
|
---|
| 43 | Dim session, progress
|
---|
[26502] | 44 |
|
---|
[21569] | 45 | Set session = CreateObject("VirtualBox.Session")
|
---|
| 46 | vb.openExistingSession session, mach.id
|
---|
| 47 | session.console.powerDown().waitForCompletion(-1)
|
---|
| 48 | session.close()
|
---|
| 49 | End Sub
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | Sub Main
|
---|
| 53 | Dim vb, mach
|
---|
[26502] | 54 |
|
---|
[21569] | 55 | set vb = CreateObject("VirtualBox.VirtualBox")
|
---|
| 56 | Print "VirtualBox version " & vb.version
|
---|
| 57 |
|
---|
[26502] | 58 | ' Safe arrays not fully functional from Visual Basic Script, as we
|
---|
[21569] | 59 | ' return real safe arrays, not ones wrapped to VARIANT and VBS engine
|
---|
| 60 | ' gets confused. Until then, explicitly find VM by name.
|
---|
[26502] | 61 | ' May wish to use hack like one described in
|
---|
[21569] | 62 | ' http://www.tech-archive.net/Archive/Excel/microsoft.public.excel.programming/2006-05/msg02796.html to handle safearrays
|
---|
| 63 | ' if desperate
|
---|
| 64 |
|
---|
| 65 | Set mach = vb.findMachine("Win")
|
---|
| 66 | Print "Machine: " & mach.name & " ID: " & mach.id
|
---|
[26502] | 67 |
|
---|
[21569] | 68 | StartVm vb, mach
|
---|
| 69 | End Sub
|
---|
| 70 |
|
---|
| 71 | Main
|
---|
[69257] | 72 |
|
---|