1 | ' $Id: vboxinfo.vbs 93115 2022-01-01 11:31:46Z vboxsync $
|
---|
2 | '' @file
|
---|
3 | ' ???
|
---|
4 | '
|
---|
5 |
|
---|
6 | '
|
---|
7 | ' Copyright (C) 2009-2022 Oracle Corporation
|
---|
8 | '
|
---|
9 | ' This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ' available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ' you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ' General Public License (GPL) as published by the Free Software
|
---|
13 | ' Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ' VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ' hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | '
|
---|
17 |
|
---|
18 | Sub Print(str)
|
---|
19 | Wscript.Echo str
|
---|
20 | End Sub
|
---|
21 |
|
---|
22 | Sub StartVm(vb, mach)
|
---|
23 | Dim session, progress
|
---|
24 |
|
---|
25 | Set session = CreateObject("VirtualBox.Session")
|
---|
26 | Set progress = vb.openRemoteSession(session, mach.id, "gui", "")
|
---|
27 | progress.waitForCompletion(-1)
|
---|
28 | session.close()
|
---|
29 | End Sub
|
---|
30 |
|
---|
31 |
|
---|
32 | Sub StopVm(vb, mach)
|
---|
33 | Dim session, progress
|
---|
34 |
|
---|
35 | Set session = CreateObject("VirtualBox.Session")
|
---|
36 | vb.openExistingSession session, mach.id
|
---|
37 | session.console.powerDown().waitForCompletion(-1)
|
---|
38 | session.close()
|
---|
39 | End Sub
|
---|
40 |
|
---|
41 |
|
---|
42 | Sub Main
|
---|
43 | Dim vb, mach
|
---|
44 |
|
---|
45 | set vb = CreateObject("VirtualBox.VirtualBox")
|
---|
46 | Print "VirtualBox version " & vb.version
|
---|
47 |
|
---|
48 | ' Safe arrays not fully functional from Visual Basic Script, as we
|
---|
49 | ' return real safe arrays, not ones wrapped to VARIANT and VBS engine
|
---|
50 | ' gets confused. Until then, explicitly find VM by name.
|
---|
51 | ' May wish to use hack like one described in
|
---|
52 | ' http://www.tech-archive.net/Archive/Excel/microsoft.public.excel.programming/2006-05/msg02796.html to handle safearrays
|
---|
53 | ' if desperate
|
---|
54 |
|
---|
55 | Set mach = vb.findMachine("Win")
|
---|
56 | Print "Machine: " & mach.name & " ID: " & mach.id
|
---|
57 |
|
---|
58 | StartVm vb, mach
|
---|
59 | End Sub
|
---|
60 |
|
---|
61 | Main
|
---|
62 |
|
---|