home *** CD-ROM | disk | FTP | other *** search
- //
- // VmCOM JScript Sample Script (sample1)
- // Copyright 1998 VMware, Inc. All rights reserved. -- VMware Confidential
- //
- // Permission is hereby granted, free of charge, to any person obtaining a
- // copy of the software in this file (the "Software"), to deal in the
- // Software without restriction, including without limitation the rights to
- // use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // The names "VMware" and "VMware, Inc." must not be used to endorse or
- // promote products derived from the Software without the prior written
- // permission of VMware, Inc.
- //
- // Products derived from the Software may not be called "VMware", nor may
- // "VMware" appear in their name, without the prior written permission of
- // VMware, Inc.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- // VMWARE,INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // ------
- //
- // This program is for educational purposes only.
- // It is not to be used in production environments.
- //
- // Description:
- //
- // This script displays the virtual machines on the local server.
- // It prints the configuration file path and current execution
- // state of each VM. If a VM is in the stuck state, the current
- // question and its choices are also printed.
- //
- // Instructions for Windows 2000 and later operating systems:
- //
- // - save the contents of this file to a file named 'sample1.js'
- // unless it's already named that way
- //
- // - there should be an accompanying file named 'sample1.wsf'
- // It is placed in the same directory as this file during
- // product installation. This file is responsible for setting
- // up the Windows Script Host environment and loading the
- // VmCOM type library, thereby enabling this script to
- // reference symbolic constants such as vmExecutionState_On
- //
- // - in a command line window, type:
- // cscript //nologo sample1.wsf
- //
-
- cp = WScript.CreateObject("VmCOM.VmConnectParams");
- server = WScript.CreateObject("VmCOM.VmServerCtl");
- server.Connect(cp)
- vmCollection = server.RegisteredVmNames
-
- for (j = 1; j <= vmCollection.count; j++) {
-
- vmName = vmCollection(j);
- vm = WScript.CreateObject("VmCOM.VmCtl");
- str = "config path=" + vmName;
- connectFailed = false
- try {
- vm.Connect(cp, vmName);
- }
- catch (e) {
- if (e.number == vmErr_VMBUSY) {
- str += " UNAVAILABLE (controlled by local console)"
- } else {
- str += " ERROR CONNECTING desc='" + e.description + "'"
- }
- connectFailed = true
- }
- if (connectFailed) {
- WScript.Echo(str);
- continue;
- }
- // Past this point, exceptions are unhandled and fatal
-
- str += " OS=" + vm.Config("guestOS") + " state=";
- execStateString = State2Str(vm);
- str += execStateString;
-
- if (execStateString == "STUCK") {
-
- question = vm.PendingQuestion;
- str += " pending question='" + question.text + "' choices=";
-
- choices = question.choices
- for (i = 1; i <= choices.count; i ++) {
- str += "[" + choices(i) + "] ";
- }
- }
- WScript.Echo(str);
- }
-
- function State2Str(vm) {
- switch (vm.ExecutionState) {
- case vmExecutionState_On:
- return "ON";
- break;
- case vmExecutionState_Off:
- return "OFF";
- break;
- case vmExecutionState_Suspended:
- return "SUSPENDED";
- break;
- case vmExecutionState_Stuck:
- return "STUCK";
- break;
- default:
- return "UNKNOWN";
- break;
- }
- }
-