Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

  1. <HTML>
  2. <HEAD>
  3. <TITLE>Sample page showing the use of the WMIObjectBroker</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <br>
  7. Click <SPAN id=ShowProcessesOld><b>HERE</b></SPAN> to use WMI only to show a list of processes<br>
  8. Click <SPAN id=ShowProcesses><b>HERE</b></SPAN> to use broker and WMI to show a list of processes<br>
  9. <SCRIPT LANGUAGE="JSCRIPT">
  10. function UseLocator(locator)
  11. {
  12. // This function is passed a locator and displayes a message
  13. // box that lists all running services.
  14. var service = locator.ConnectServer();
  15. var procs = service.InstancesOf("Win32_Process");
  16. var f = new Enumerator(procs);
  17. sz = "";
  18. for (;!f.atEnd();f.moveNext())
  19. {
  20. var proc = f.item();
  21. sz += proc["Name"] + "\r\n";
  22. }
  23. alert(sz);
  24. }
  25. function ShowProcessesOld.onclick()
  26. {
  27. var registrar;
  28. var broker;
  29. var locator;
  30. try
  31. {
  32. locator = new ActiveXObject("WbemScripting.SWbemLocator");
  33. }
  34. catch(e)
  35. {
  36. }
  37. if(locator == null)
  38. alert("Unable to create WMI object");
  39. else
  40. UseLocator(locator)
  41. }
  42. function ShowProcesses.onclick()
  43. {
  44. var registrar;
  45. var broker;
  46. var locator;
  47. try
  48. {
  49. // This should have no trouble since the broker is safe for scripting
  50. var broker = new ActiveXObject("WMIScriptUtils.WMIObjectBroker");
  51. // If we are not already registered to create a locator, try to register our self
  52. if(!broker.CanCreateObject("WbemScripting.SWbemLocator"))
  53. {
  54. registrar = new ActiveXObject("WMIScriptUtils.WMIObjectBrokerRegistration");
  55. registrar.Register("WbemScripting.SWbemLocator");
  56. }
  57. // If we were already registered, the following command will create
  58. // a locator without complaint. If we could not register (for example,
  59. // we were not run from a local hard drive), the following command
  60. // behaives just like 'new ActiveXObject' with all the same IE
  61. // warnings and errors
  62. locator = broker.CreateObject("WbemScripting.SWbemLocator");
  63. }
  64. catch(e)
  65. {
  66. }
  67. if(locator == null)
  68. alert("Unable to create WMI object");
  69. else
  70. UseLocator(locator)
  71. }
  72. </SCRIPT>
  73. </BODY>
  74. </HTML>