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.
72 lines
1.6 KiB
72 lines
1.6 KiB
<HTML>
|
|
<HEAD>
|
|
<TITLE>Sample page showing the use of the WMIObjectBroker</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<SCRIPT LANGUAGE="JSCRIPT">
|
|
var broker = new ActiveXObject("WMIScriptUtils.WMIObjectBroker");
|
|
var register = false
|
|
if(!broker.CanCreateObject("WbemScripting.SWbemLocator"))
|
|
register = true;
|
|
if(!broker.CanCreateObject("WbemScripting.SWbemNamedValue"))
|
|
register = true;
|
|
if(!broker.CanCreateObject("WbemScripting.SWbemNamedValueSet"))
|
|
register = true;
|
|
if(register)
|
|
{
|
|
var registrar;
|
|
try
|
|
{
|
|
registrar = new ActiveXObject("WMIScriptUtils.WMIObjectBrokerRegistration");
|
|
registrar.Register("WbemScripting.SWbemLocator");
|
|
registrar.Register("WbemScripting.SWbemNamedValue");
|
|
registrar.Register("WbemScripting.SWbemNamedValueSet");
|
|
}
|
|
catch(e)
|
|
{
|
|
}
|
|
}
|
|
|
|
</SCRIPT>
|
|
<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 locator;
|
|
try
|
|
{
|
|
locator = broker.CreateObject("WbemScripting.SWbemLocator");
|
|
}
|
|
catch(e)
|
|
{
|
|
}
|
|
if(locator == null)
|
|
alert("Unable to create WMI object");
|
|
else
|
|
UseLocator(locator)
|
|
}
|
|
</SCRIPT>
|
|
|
|
</BODY>
|
|
</HTML>
|