2025-04-27 07:49:33 -04:00

764 lines
22 KiB
HTML

<html><head>
<title>WMI Event Provider Wizard</title>
<style type="text/css">@import "..\..\..\..\..\1033\styles.css";
</style>
</head>
<body onkeydown=OnKey(); style="OVERFLOW: visible" bottomMargin=0
bgColor=#ebebeb leftMargin=0 topMargin=0 onload=InitDocument(document);
rightMargin=0>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%">
<TR align=top>
<TD height="100%">
<TABLE bgcolor="white" style="width:100%;height:65;border-style:solid;border-color:silver;border-width:1;" align=top>
<TR>
<TD>
<DIV>
<P class="titleText">WMI Event Provider Wizard</P>
<P class="titleDesc">Specify...</P>
</DIV>
</TD>
<TD>
<DIV id="Layer1" style="z-index:1" align=right>
<IMG src="..\..\Images\Overview.bmp" width="92" height="63"></IMG>
</DIV>
</TD>
</TR>
</TABLE>
<TABLE style="BORDER-BOTTOM: silver 1px solid" height="70%" cellSpacing=0
cellPadding=0 width="100%" bgColor=#ebebeb>
<TBODY>
<TR>
<TD style="WIDTH: 187px" vAlign=top align=left>
<TABLE style="WIDTH: 200px; HEIGHT: 280px" align=left
bgColor=#ebebeb>
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=silver
><span class=sideBtn id=Default
onmouseover="this.style.color='blue'; this.style.cursor='hand'"
title="" onclick='Next(document, "default.htm");'
onmouseout="this.style.color='black'"><b
><LABEL for=Default
>Names</LABEL></b></span></TD></TR>
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=#ebebeb
><span class=sideBtn id=WMIClass
onmouseover="this.style.color='blue'; this.style.cursor='hand'"
title="" onclick='Next(document, "WMIClass.htm");'
onmouseout="this.style.color='black'"
><LABEL for=WMIClass
>WMI Class</LABEL></span></TD></TR>
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=silver
><span class=sideBtn id=Attributes
onmouseover="this.style.color='blue'; this.style.cursor='hand'"
title="" onclick='Next(document, "Attributes.htm");'
onmouseout="this.style.color='black'"
><LABEL for=Attributes
>Attributes</LABEL></span></TD></TR>
<!--
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=silver
><span class=sideBtn id=Properties
onmouseover="this.style.color='blue'; this.style.cursor='hand'"
title="" onclick='Next(document, "Properties.htm");'
onmouseout="this.style.color='black'"
><LABEL for=Properties
>Properties</LABEL></SPAN></TD></TR>-->
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=silver
><span></span></TD></TR>
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=silver
><span></span></TD></TR>
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=silver
><span></span></TD></TR>
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=silver
><span></span></TD></TR>
<TR>
<TD class=bodyText style="HEIGHT: 13%" bgColor=silver
><span
></span></TD></TR></TABLE>
<!-- two invisible test boxes to store ns and classname-->
<input class=itemText
id=NAMESPACE name=NAMESPACE style="display:none"> </input><input
class=itemText id=WMICLASSNAME name=WMICLASSNAME style="display:none">
</input>
<table style="HEIGHT: 170px" width="100%" align=center
>
<TBODY>
<tr align=middle>
<td class=sideBtn style="HEIGHT: 50px" vAlign=top width="50%"
>
<p class=itemText><span class=itemText
><span><b
>Select event type:</b></span><br
><span class=itemText
><input id=INTRINSIC title="" accessKey=i
onclick=OnChangeNS() type=radio name=eventtype
><span title=""
><LABEL for=INTRINSIC
><u>I</u>ntrinsic
events </LABEL></span></span><span class=itemText
><input id=EXTRINSIC title="" accessKey=E
onclick=OnChangeNS() type=radio name=eventtype
CHECKED><span title=""
><LABEL for=EXTRINSIC
><u>E</u>xtrinsic
events</LABEL></span><br
></span></span></p></td></tr>
<tr align=left>
<td>
<p class=itemText style="WIDTH: 234px; HEIGHT: 12px"
><span class=itemText
><b>Select
<u>n</u>amespace:</b></span><br><select
class=itemText id=NSPICKER style="WIDTH: 370px; HEIGHT: 13%"
onchange=OnChangeNS() align=left size=1 name=NSPICKER accessKey=n
TYPE="SELECT-ONE"> <option value=1
selected>root</option></select></SPAN>
</p></td></tr>
<tr>
<td align=left><br>
<p class=itemText><span class=itemText
><b>Select
c<u>l</u>ass:</b></span><br><input
class=sideBtn onkeypress=OnInputKeyPress()
oncut=OnInputKeyPress() onpaste=OnInputKeyPress()
id=CLASSINPUT style="WIDTH: 369px" name=CLASSINPUT
>
<select class=itemText id=CLASSPICKER
ondblclick=OnClassDblClick()
style="WIDTH: 369px; HEIGHT: 60px"
onchange=OnChangeSelection() align=left size=12
name=CLASSPICKER accessKey=l
TYPE="SELECT-ONE"></select></SPAN></p></td></tr>
<tr align=left>
<td><br><span
class=itemText title=""><LABEL
for=CURRENTSELECTION><b
>Current selection:</b><BR> </LABEL>
<TEXTAREA class=itemText id=CURRENTSELECTION style="OVERFLOW: visible; WIDTH: 369px; HEIGHT: 12px" readOnly></TEXTAREA></span>
</td></tr></TBODY></table></TD></TR></TBODY></TABLE>
<TABLE style="width:100%;height:10%" cellpadding=0 cellspacing=4>
<TR>
<TD align=left width=85%></TD>
<TD align=right width=5%>
<BUTTON id="HelpBtn" class="buttonClass" ACCESSKEY="h" onClick='window.external.Alert("Sorry, no help is available for this wizard.");'><u>H</u>elp</BUTTON>
</TD>
<TD align=right width=5%>
<BUTTON id="FinishBtn" class="buttonClass" ACCESSKEY="f" onClick='OnFinish(this);'><u>F</u>inish</BUTTON>
</TD>
<TD align=right width=5%>
<BUTTON id="CancelBtn" class="buttonClass" ACCESSKEY="c" onClick='window.external.Finish(document, "cancel");'><u>C</u>ancel</BUTTON>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<SCRIPT language=jscript>
var tab_array = new Array();
tab_array[0] = Default;
tab_array[1] = WMIClass;
tab_array[2] = Attributes;
//tab_array[3] = Properties;
var arCodeComments = new Array();
arCodeComments[0] = "//TODO: put appropriate value here";
var dictCIM2VT = new ActiveXObject("Scripting.Dictionary");
dictCIM2VT.Add("2", "VT_I2"); //wbemCimtypeSint16
dictCIM2VT.Add("3", "VT_I4"); //wbemCimtypeSint32
dictCIM2VT.Add("4", "VT_R4"); //wbemCimtypeReal32
dictCIM2VT.Add("5", "VT_R8"); //wbemCimtypeReal64
dictCIM2VT.Add("8", "VT_BSTR"); //wbemCimtypeString
dictCIM2VT.Add("11", "VT_BOOL"); //wbemCimtypeBoolean
dictCIM2VT.Add("13", "VT_UNKNOWN"); //wbemCimtypeObject
dictCIM2VT.Add("16", "VT_I2"); //wbemCimtypeSint8
dictCIM2VT.Add("17", "VT_UI1"); //wbemCimtypeUint8
dictCIM2VT.Add("18", "VT_I4"); //wbemCimtypeUint16
dictCIM2VT.Add("19", "VT_I4"); //wbemCimtypeUint32
dictCIM2VT.Add("20", "VT_BSTR"); //wbemCimtypeSint64
dictCIM2VT.Add("21", "VT_BSTR"); //wbemCimtypeUint64
dictCIM2VT.Add("101", "VT_BSTR"); //wbemCimtypeDatetime
dictCIM2VT.Add("102", "VT_BSTR"); //wbemCimtypeReference
dictCIM2VT.Add("103", "VT_I2"); //wbemCimtypeChar16
var propPrefix = "s_pProp";
var locator;
var services;
var classSink = InternalGetObject("WbemScripting.SWbemSink");
var arClassNames;
var dictLookup;
var bRestoreClassSelection = false;
function InitDocument(document)
{
try
{
var bFirstLoad = window.external.FindSymbol("DOCUMENT_FIRST_LOAD");
if (bFirstLoad)
{
window.external.SetDefaults(document);
}
window.external.Load(document);
locator = InternalGetObject("WbemScripting.SWbemLocator");
EnumNamespaces("root", 1);
CURRENTSELECTION.value = "";
bRestoreClassSelection = true;
//force selection of the last selected namespace and class
//or the first elements in both listboxes
RestoreNSSelection();
OnChangeNS();
}
catch (e)
{
window.external.ReportError("Exception: " + e.description + " in InitDocument()");
}
}
function EnumNamespaces(name, num)
//recursively adds namespaces to the drop-down box
{
try
{
services = locator.ConnectServer("", name);
var instances = new Enumerator(services.InstancesOf("__NAMESPACE"));
for (; !instances.atEnd(); instances.moveNext() )
{
num++;
var oOption = document.createElement("OPTION");
NSPICKER.options.add(oOption);
var NameOut;
if (name != "")
{
NameOut = name + "\\" + instances.item().Name;
}
else
{
NameOut = instances.item().Name;
}
oOption.innerText = NameOut;
oOption.Value = num;
EnumNamespaces(NameOut, num);
}
}
catch (e)
{
window.external.ReportError("Exception: " + e.description + " in EnumNamespaces()");
return;
}
}
function OnChangeNS()
//clear array and dictionary, then call asynchronous class enumeration
{
try
{
//cancel any pending asynchronous requests
classSink.Cancel();
//clear CLASSPICKER and CLASSINPUT first
while (CLASSPICKER.options.length > 0)
{
CLASSPICKER.options.remove(0);
}
CLASSINPUT.value = "";
//clear class names array and dictionary
arClassNames = "";
arClassNames = new Array();
dictLookup = "";
dictLookup = new ActiveXObject("Scripting.Dictionary");
//Display "Loading classes..." in the class list box
var oOption = document.createElement("OPTION");
CLASSPICKER.options.add(oOption);
oOption.innerText = "Loading classes...";
oOption.Value = 1;
var strNS = NSPICKER[NSPICKER.selectedIndex].innerText;
services = locator.ConnectServer("", strNS);
document.body.style.cursor = 'wait';
services.SubclassesOfAsync(classSink);
}
catch (e)
{
window.external.ReportError("Exception: " + e.description + " in OnChangeNS()");
}
}
function OnInputKeyPress()
//selects best-matching class in the listbox
{
//update text immediately, without waiting for rather lengthy processing
//CLASSINPUT.value += String.fromCharCode(event.keyCode);
try
{
var strInput = CLASSINPUT.value.toUpperCase();
var bLoopThrough = true;
for (i = 0; i < CLASSPICKER.options.length; i++)
{
var strListed = CLASSPICKER.options[i].innerText.toUpperCase();
if (strListed >= strInput)
{
CLASSPICKER.selectedIndex = i;
bLoopThrough = false;
break;
}
}
if (bLoopThrough)
{
//select the last line
CLASSPICKER.selectedIndex = CLASSPICKER.options.length - 1;
}
//we already updated text, so no need to add the character again:
//event.returnValue=false;
}
catch (e)
{
window.external.ReportError("Exception: " + e.description + " in OnInputKeyPress()");
}
}
function OnChangeSelection()
//display selected value in CLASSINPUT box
{
try
{
if (CLASSPICKER.selectedIndex == -1)
{
return;
}
var selectionValue = CLASSPICKER[CLASSPICKER.selectedIndex].innerText;
//check to see if the selected string is a class name (i.e., appears in the map)
if (!dictLookup.Exists(selectionValue.toUpperCase()))
{
return;
}
CLASSINPUT.value = selectionValue;
}
catch (e)
{
window.external.ReportError("Exception: " + e.description + " in OnChangeSelection");
}
}
function OnClassDblClick()
{
try
{
var selNamespace = NSPICKER[NSPICKER.selectedIndex].innerText;
var selClassName = CLASSPICKER[CLASSPICKER.selectedIndex].innerText;
if (EXTRINSIC.checked)
{
//see if the class already has a "provider" qualifier and warn
var classObj = services.Get(selClassName);
var strCurrentProv = GetCurrentProviderName(classObj);
if (strCurrentProv != "")
{
var bReplaceProv = confirm ("Warning: this class already has a provider: " +
strCurrentProv + ". Replacing the existing provider could could be dangerous. Are you sure you want to do this?");
if (!bReplaceProv)
{
return;
}
}
}
else
{
//BUGBUG(?): there is no easy way to determine if there is an intrinsic event provider.
//Also, if the class doesn't have one, winmgmt is polling instance data and firing instrinsic
//events. Registering a provider causes winmgmt to stop polling and so this will break
//potential consumers. We will therefore ALWAYS bring up a warning for intrinsic providers:
var bRegisterProv = confirm ("Warning: unless you created class \"" + selClassName + "\", it is strongly advised that you do NOT register an intrinsic event provider for it. Doing so may seriously affect your system. Are you sure you want to do this?");
if (!bRegisterProv)
{
return;
}
}
var selectionValue = selNamespace + " : " + selClassName;
//check to see if the selected string is a class name (i.e., appears in the map)
if (!dictLookup.Exists(selClassName.toUpperCase()))
return;
CURRENTSELECTION.value = selectionValue;
NAMESPACE.value = selNamespace;
WMICLASSNAME.value = selClassName;
}
catch(e)
{
window.external.ReportError("Exception: " + e.description + " in OnClassDblClick");
}
}
function OnUnload()
{
}
function Next(document, linkto)
{
GetWMIClassInfo();
window.external.Next(document, linkto);
}
function OnFinish(obj)
{
GetWMIClassInfo();
obj.style.cursor='wait';
window.external.Finish(document, "ok");
}
function InternalGetObject(progID)
{
try
{
var broker = new ActiveXObject("WMIScriptUtils.WMIObjectBroker");
if (broker.CanCreateObject(progID))
{
return broker.CreateObject(progID);
}
else
{
var registrar = new ActiveXObject("WMIScriptUtils.WMIObjectBrokerRegistration");
registrar.Register(progID);
return broker.CreateObject(progID);
}
}
catch (e)
{
window.external.ReportError ("Error in GetLocator(): " + e.description);
}
}
function RestoreNSSelection()
{
try
{
//select saved namespace in NSPICKER
for (i = 0; i < NSPICKER.options.length; i++)
{
var strCurrent = NSPICKER.options[i].innerText;
if (strCurrent == NAMESPACE.value)
{
NSPICKER.selectedIndex = i;
//fill CURRENTSELECTION box:
CURRENTSELECTION.value = NAMESPACE.value + " : ";
return;
}
}
//or, just select the first index
NSPICKER.selectedIndex = 0;
}
catch(e)
{
window.external.ReportError ("Error in RestoreNSSelection(): " + e.description);
}
}
function RestoreClassSelection()
{
try
{
var bRestored = false;
//select saved class in CLASSPICKER
for (i = 0; i < CLASSPICKER.options.length; i++)
{
var strCurrent = CLASSPICKER.options[i].innerText;
if (strCurrent == WMICLASSNAME.value)
{
CLASSPICKER.selectedIndex = i;
//fill CURRENTSELECTION box:
CURRENTSELECTION.value += WMICLASSNAME.value;
bRestored = true;
break;
}
}
//or, just select the first index
if (!bRestored)
{
CLASSPICKER.selectedIndex = 0;
}
//update CLASSINPUT
OnChangeSelection();
}
catch(e)
{
window.external.ReportError ("Error in RestoreClassSelection(): " + e.description);
}
}
</SCRIPT>
<script language=JScript>
function classSink::OnObjectReady(objObject, objAsyncContext)
{
//Filter out classes according to event provider type.
//Put each qualifying object's class name into an array (in the uppercase)
//and a dictionary, mapping uppercase and case-preservant names
try
{
var bIntrinsic = INTRINSIC.checked;
var bExtrinsic = EXTRINSIC.checked;
if (bIntrinsic)
{
//filter out abstract, system and event classes
//NOTE: ALL EVENT CLASSES ARE ABSTRACT
if (CheckBoolQualifier(objObject, "abstract") || IsSystem(objObject))
return;
}
if (bExtrinsic)
{
//filter out all classes that are not derived
//from __ExtrinsicEvent. And all system classes, too.
if (!IsExtrinsicEvent(objObject) || IsSystem(objObject))
return;
}
var NameOut = objObject.Path_.RelPath;
arClassNames[arClassNames.length] = NameOut.toUpperCase();
dictLookup.Add (NameOut.toUpperCase(), NameOut);
}
catch(e)
{
window.external.ReportError("Exception " + e.description + " in OnObjectReady()");
}
}
function classSink::OnCompleted(objObject, objAsyncContext)
{
//sort the uppercase array; pull case-preservant names from the dictionary
//and display them
try
{
//clear "Loading..." text from CLASSPICKER
while (CLASSPICKER.options.length > 0)
{
CLASSPICKER.options.remove(0);
}
arClassNames.sort();
for (i = 0; i < arClassNames.length; i++)
{
var oOption = document.createElement("OPTION");
CLASSPICKER.options.add(oOption);
oOption.innerText = dictLookup.Item(arClassNames[i]);
oOption.Value = i + 1;
}
if (bRestoreClassSelection) //first enumeration after InitDocument()
{
RestoreClassSelection();
bRestoreClassSelection = false;
}
else
{
//force selection of the first class in the list
CLASSPICKER.selectedIndex = 0;
OnChangeSelection();
}
document.body.style.cursor = 'default';
}
catch(e)
{
window.external.ReportError ("Exception " + e.description + " in OnCompleted()");
}
}
function IsExtrinsicEvent(objObject)
{
try
{
//handle __ExtrinsicEvent class separately, since it is not its own parent
if (objObject.Path_.RelPath.toString() == "__ExtrinsicEvent")
{
return true;
}
arVB = new VBArray(objObject.Derivation_);
arJS = arVB.toArray();
for (i =0; i < arJS.length; i++)
{
if (arJS[i].toString() == "__ExtrinsicEvent")
{
return true;
}
}
return false;
}
catch (e)
{
window.external.ReportError ("Error in IsExtrinsicEvent() " + objObject);
return false;
}
}
function CheckBoolQualifier (obj, qualName)
{
try
{
var qual = obj.Qualifiers_(qualName);
return (qual.Value);
}
catch(e)
{
//NOTE that if the qualifier is not present, "Not found" will be returned
//Return false in this case
return false;
}
}
function GetCurrentProviderName (obj)
{
//checks if the class already has a "provider" qualifier value and returns it.
//if the class doesn't have a "provider" qualifier or its value is empty, an empty string is
//returned.
try
{
var qual = obj.Qualifiers_("provider");
return (qual.Value.toString());
}
catch(e)
{
//NOTE that if the qualifier is not present, "Not found" will be returned
//Return empty string in this case
return "";
}
}
function IsSystem(objObject)
{
try
{
var NameOut = objObject.Path_.RelPath;
return (NameOut.slice(0, 2).toString() == "__");
}
catch(e)
{
return false;
}
}
function GetWMIClassInfo()
{
try
{
if (WMICLASSNAME.value == "")
return;
var classObj = services.Get(WMICLASSNAME.value);
if (EXTRINSIC.checked)
{
//Create EXTRINSIC_PUT_BLOCK:
var strExtrinsicPutBlock = "CComVariant var;\n\r";
var strExtrPropertyDecls = "";
var strExtrPropertyDefs = "";
var props = new Enumerator (classObj.Properties_);
for (; !props.atEnd(); props.moveNext() )
{
strExtrPropertyDecls += "extern const WCHAR * " + propPrefix + props.item().Name + ";\n\r";
strExtrPropertyDefs += "const static WCHAR * " + propPrefix + props.item().Name +
" = L\"" + props.item().Name + "\";\n\r";
var vt = dictCIM2VT.Item(props.item().CIMType.toString());
if (props.item().IsArray) {
vt += " | VT_ARRAY";
}
strExtrinsicPutBlock += " var.ChangeType(" + vt + ");\n\r";
strExtrinsicPutBlock += " //var = <value>;" + arCodeComments[0] + "\n\r";
strExtrinsicPutBlock += " hr = pEvtInstance->Put(" + propPrefix + props.item().Name +
", 0, &var, 0);\n\r";
strExtrinsicPutBlock += " var.Clear();\n\r\n\r";
}
window.external.AddSymbol("EXTRINSIC_PUT_BLOCK", strExtrinsicPutBlock);
window.external.AddSymbol("EXTR_PROPERTY_DEFINITIONS", strExtrPropertyDefs);
window.external.AddSymbol("EXTR_PROPERTY_DECLARATIONS", strExtrPropertyDecls);
}
}
catch(e)
{
window.external.ReportError ("Error in GetWMIClassInfo():" + e);
}
}
</script>
</TD></TR></TABLE>
<SCRIPT SRC="..\..\..\..\..\1033\common.js">
</SCRIPT>
</body></html>