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.

71 lines
1.6 KiB

  1. <HTML>
  2. <HEAD>
  3. <TITLE>Sample page showing the use of the WMIObjectBroker</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <SCRIPT LANGUAGE="JSCRIPT">
  7. var broker = new ActiveXObject("WMIScriptUtils.WMIObjectBroker");
  8. var register = false
  9. if(!broker.CanCreateObject("WbemScripting.SWbemLocator"))
  10. register = true;
  11. if(!broker.CanCreateObject("WbemScripting.SWbemNamedValue"))
  12. register = true;
  13. if(!broker.CanCreateObject("WbemScripting.SWbemNamedValueSet"))
  14. register = true;
  15. if(register)
  16. {
  17. var registrar;
  18. try
  19. {
  20. registrar = new ActiveXObject("WMIScriptUtils.WMIObjectBrokerRegistration");
  21. registrar.Register("WbemScripting.SWbemLocator");
  22. registrar.Register("WbemScripting.SWbemNamedValue");
  23. registrar.Register("WbemScripting.SWbemNamedValueSet");
  24. }
  25. catch(e)
  26. {
  27. }
  28. }
  29. </SCRIPT>
  30. <br>
  31. Click <SPAN id=ShowProcesses><b>HERE</b></SPAN> to use WMI to show a list of processes<br>
  32. <SCRIPT LANGUAGE="JSCRIPT">
  33. function UseLocator(locator)
  34. {
  35. // This function is passed a locator and displayes a message
  36. // box that lists all running services.
  37. var service = locator.ConnectServer();
  38. var procs = service.InstancesOf("Win32_Process");
  39. var f = new Enumerator(procs);
  40. sz = "";
  41. for (;!f.atEnd();f.moveNext())
  42. {
  43. var proc = f.item();
  44. sz += proc["Name"] + "\r\n";
  45. }
  46. alert(sz);
  47. }
  48. function ShowProcesses.onclick()
  49. {
  50. var locator;
  51. try
  52. {
  53. locator = broker.CreateObject("WbemScripting.SWbemLocator");
  54. }
  55. catch(e)
  56. {
  57. }
  58. if(locator == null)
  59. alert("Unable to create WMI object");
  60. else
  61. UseLocator(locator)
  62. }
  63. </SCRIPT>
  64. </BODY>
  65. </HTML>