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