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.
 
 
 
 
 
 

109 lines
3.9 KiB

<HTML>
<HEAD>
<TITLE>Sample page showing the use of the WMIObjectBroker</TITLE>
<OBJECT ID="staticbroker" CLASSID="CLSID:4BA59771-8FBF-4E67-9917-3BBB39B743AB"></OBJECT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JSCRIPT">
var broker = new ActiveXObject("WMIScriptUtils.WMIObjectBroker");
if(broker.CanCreateObject("WbemScripting.SWbemLocator"))
document.writeln("This page CAN freely create an SWbemLocator<br>");
else
document.writeln("This page CAN NOT create an SWbemLocator without warning<br>");
if(broker.CanCreateObject("WbemScripting.SWbemNamedValue"))
document.writeln("This page CAN freely create an SWbemNamedValue<br>");
else
document.writeln("This page CAN NOT create an SWbemNamedValue without warning<br>");
if(broker.CanCreateObject("WbemScripting.SWbemNamedValueSet"))
document.writeln("This page CAN freely create an SWbemNamedValueSet<br>");
else
document.writeln("This page CAN NOT create an SWbemNamedValueSet without warning<br>");
</SCRIPT>
<br>
<!This message will only show up if either SWbemLocator or SWbemNamedValue is not currently registered for this page>
<SPAN id=RegisterSpan>
Click <SPAN id=ClickRegister><b>HERE</b></SPAN> to register this page to freely create SWbemLocator or SWbemNamedValue.
Since this operation modifies the registry, IE will prompt you with a security dialog before it allows the operation to
be completed.<br>
<br>
</SPAN>
<!This message will only show up if both SWbemLocator and SWbemNamedValue are registered for this page>
<SPAN id=UnRegisterSpan>
Click <SPAN id=ClickUnRegister><b>HERE</b></SPAN> to UNregister this page to from freely creating SWbemLocator or SWbemNamedValue objects.
Since this operation modifies the registry, IE will prompt you with a security dialog before it allows the operation to
be completed.<br>
<br>
</SPAN>
Click <SPAN id=ShowProcesses><b>HERE</b></SPAN> to use WMI to show a list of properties. If this page is registered to freely create SWbemLocator objects, this will work
without any warnings. If this page is not registered, you'll see an IE warning before the operation is completed.<br>
<SCRIPT LANGUAGE="JSCRIPT">
function InternalCreateObject(ProgId)
{
// This function will try to create the object specified by ProgId without
// causing any security warnings if possible. Otherwise, it will just create
// the object normally
var broker = new ActiveXObject("WMIScriptUtils.WMIObjectBroker");
if(broker.CanCreateObject(ProgId))
return broker.CreateObject(ProgId);
return new ActiveXObject(ProgId);
}
function window.onload()
{
var broker = new ActiveXObject("WMIScriptUtils.WMIObjectBroker");
if(broker.CanCreateObject("WbemScripting.SWbemLocator") && broker.CanCreateObject("WbemScripting.SWbemNamedValue"))
RegisterSpan.style.display="none";
else
UnRegisterSpan.style.display="none";
}
function ClickRegister.onclick()
{
var registrar = new ActiveXObject("WMIScriptUtils.WMIObjectBrokerRegistration");
registrar.Register("WbemScripting.SWbemLocator");
registrar.Register("WbemScripting.SWbemNamedValue");
window.location.reload();
}
function ClickUnRegister.onclick()
{
var registrar = new ActiveXObject("WMIScriptUtils.WMIObjectBrokerRegistration");
registrar.UnRegister("WbemScripting.SWbemLocator");
registrar.UnRegister("WbemScripting.SWbemNamedValue");
window.location.reload();
}
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 obj = InternalCreateObject("WbemScripting.SWbemLocator");
UseLocator(obj)
}
</SCRIPT>
</BODY>
</HTML>