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.

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