home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 April / PCpro_2007_04.ISO / files / usb / VMware-server-installer101.exe / sample1.js < prev    next >
Encoding:
Text File  |  2006-08-09  |  4.1 KB  |  122 lines

  1. // 
  2. //  VmCOM JScript Sample Script (sample1)
  3. //  Copyright 1998 VMware, Inc.  All rights reserved. -- VMware Confidential
  4. //  
  5. //  Permission is hereby granted, free of charge, to any person obtaining a
  6. //  copy of the software in this file (the "Software"), to deal in the
  7. //  Software without restriction, including without limitation the rights to
  8. //  use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. //  copies of the Software, and to permit persons to whom the Software is
  10. //  furnished to do so, subject to the following conditions:
  11. //  
  12. //  The above copyright notice and this permission notice shall be included in
  13. //  all copies or substantial portions of the Software.
  14. //  
  15. //  The names "VMware" and "VMware, Inc." must not be used to endorse or
  16. //  promote products derived from the Software without the prior written
  17. //  permission of VMware, Inc.
  18. //  
  19. //  Products derived from the Software may not be called "VMware", nor may
  20. //  "VMware" appear in their name, without the prior written permission of
  21. //  VMware, Inc.
  22. //  
  23. //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. //  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. //  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. //  VMWARE,INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  27. //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  28. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. //  ------
  31. //
  32. //  This program is for educational purposes only.
  33. //  It is not to be used in production environments.
  34. //
  35. //  Description:
  36. //
  37. //  This script displays the virtual machines on the local server.
  38. //  It prints the configuration file path and current execution
  39. //  state of each VM. If a VM is in the stuck state, the current
  40. //  question and its choices are also printed.
  41. //
  42. //  Instructions for Windows 2000 and later operating systems:
  43. //
  44. //  - save the contents of this file to a file named 'sample1.js'
  45. //    unless it's already named that way
  46. //
  47. //  - there should be an accompanying file named 'sample1.wsf'
  48. //    It is placed in the same directory as this file during
  49. //    product installation. This file is responsible for setting
  50. //    up the Windows Script Host environment and loading the
  51. //    VmCOM type library, thereby enabling this script to 
  52. //    reference symbolic constants such as vmExecutionState_On
  53. //
  54. //  - in a command line window, type:
  55. //    cscript //nologo sample1.wsf
  56. // 
  57.  
  58. cp = WScript.CreateObject("VmCOM.VmConnectParams");
  59. server = WScript.CreateObject("VmCOM.VmServerCtl");
  60. server.Connect(cp)
  61. vmCollection = server.RegisteredVmNames
  62.  
  63. for (j = 1; j <= vmCollection.count; j++) {
  64.  
  65.    vmName = vmCollection(j);
  66.    vm = WScript.CreateObject("VmCOM.VmCtl");
  67.    str = "config path=" + vmName;
  68.    connectFailed = false
  69.    try {
  70.       vm.Connect(cp, vmName);
  71.    }
  72.    catch (e) {
  73.       if (e.number == vmErr_VMBUSY) {
  74.          str += "  UNAVAILABLE  (controlled by local console)"
  75.       } else {
  76.          str += "  ERROR CONNECTING desc='" + e.description + "'"
  77.       }
  78.       connectFailed = true
  79.    }
  80.    if (connectFailed) {
  81.       WScript.Echo(str);
  82.       continue;
  83.    }
  84.    // Past this point, exceptions are unhandled and fatal
  85.  
  86.    str += "  OS=" + vm.Config("guestOS") + "  state="; 
  87.    execStateString = State2Str(vm);
  88.    str += execStateString;
  89.  
  90.    if (execStateString == "STUCK") {
  91.  
  92.       question = vm.PendingQuestion;
  93.       str += "  pending question='" + question.text + "' choices=";
  94.  
  95.       choices = question.choices
  96.       for (i = 1; i <= choices.count; i ++) {
  97.          str += "[" + choices(i) + "] ";
  98.       }
  99.    }
  100.    WScript.Echo(str);
  101. }
  102.  
  103. function State2Str(vm) {
  104.    switch (vm.ExecutionState) {
  105.       case vmExecutionState_On:
  106.          return "ON";
  107.      break;
  108.       case vmExecutionState_Off:
  109.          return "OFF";
  110.      break;
  111.       case vmExecutionState_Suspended:
  112.          return "SUSPENDED";
  113.      break;
  114.       case vmExecutionState_Stuck:
  115.          return "STUCK";
  116.      break;
  117.       default:
  118.          return "UNKNOWN";
  119.      break;
  120.    }
  121. }
  122.