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.
|
|
<HTML> <HEAD> <TITLE>Sample page showing the use of the WMIObjectBroker</TITLE> </HEAD> <BODY> <br>
Click <SPAN id=ShowProcesses><b>HERE</b></SPAN> to use WMI to show a list of processes<br>
<SCRIPT LANGUAGE="JSCRIPT">
function UseLocator(locator) { // This function is passed a locator and displayes a message // box that lists all running services. var service = locator.ConnectServer(); var procs = service.InstancesOf("Win32_Process"); var f = new Enumerator(procs); sz = ""; for (;!f.atEnd();f.moveNext()) { var proc = f.item(); sz += proc["Name"] + "\r\n"; } alert(sz); }
function ShowProcesses.onclick() { var registrar; var broker; var locator; try { // This should have no trouble since the broker is safe for scripting var broker = new ActiveXObject("WMIScriptUtils.WMIObjectBroker");
// If we are not already registered to create a locator, try to register our self if(!broker.CanCreateObject("WbemScripting.SWbemLocator")) { registrar = new ActiveXObject("WMIScriptUtils.WMIObjectBrokerRegistration"); registrar.Register("WbemScripting.SWbemLocator"); }
// If we were already registered, the following command will create // a locator without complaint. If we could not register (for example, // we were not run from a local hard drive), the following command // behaives just like 'new ActiveXObject' with all the same IE // warnings and errors locator = broker.CreateObject("WbemScripting.SWbemLocator"); } catch(e) { } if(locator == null) alert("Unable to create WMI object"); else UseLocator(locator) } </SCRIPT>
</BODY> </HTML>
|