CMI Script

  • Thread starter Thread starter Guest
  • Start date Start date
Hi,

I'm also messing around with the 'very well documented' CMI script.
You can create a HTML page in which will appear under settings of a
component in the TD. In this HTML page you can change settings of the
properties, resources and dependencies of a component with the help of some
VB scripting.
You can also include a VB-script. This script can contain 2 functions
OnBeginBuild and OnEndBuild.
I created a HTML page with checkboxes which set the state (bool) of some
extended properties. I use the OnBeginBuild function to disable some of the
resources of my component. My resources are generic FBA command which I use
to disable some services. The checkboxes determine which of the services are
to be disabled.

I found some the information for this at:
http://www.windowsfordevices.com/articles/AT2652672892.html
and asking a guy named Alexander to mail me an example

In the next post will contains my HTML en VBS.

Good luck
 
The HTML:

The HTML for the checkboxes are build runtime and a checkbos is made for all
extended properties that begin with "res". I kept the names for the
properties the same as the resources to make it all simple. The checkbox tag
is taken from the resource with the same name as the property. So you
something like this:

[ x ] ResourceDescription

==============================
<HTML>
<HEAD>
<STYLE TYPE="text/css">
<!--

BODY { font: normal 8pt Tahoma; background-color: #FFFFFF; }
P { font: normal 8pt Tahoma; }
TABLE { font: normal 8pt Tahoma; text-align: left; padding: 2px; }
LABEL { font: bold 8pt Tahoma; text-align: left; padding: 2px; }
TD { font: normal 8pt Tahoma; text-align: left; padding: 2px; }
TR { font: normal 8pt Tahoma; text-align: left; padding: 2px; }

-->
</STYLE>
</HEAD>
<BODY>
<hr>
<table>
<caption> </caption>
<tr><td><label for="idCWA">Services to Disable:</label></td></tr>
<tr>
<td>
<SCRIPT type="text/vbscript">
Option Explicit
Dim cmiThis : Set cmiThis = window.external.Instance

Function DisplayResources()
Dim oProp, sTmp, sName
sTmp = ""
For Each oProp In cmiThis.Properties
If Left(oProp.Name,3) = "res" Then
sTmp = sTmp + "<tr><td><input type=checkbox "
sTmp = sTmp + "name='id" + oProp.Name + "' "
If CBool(oProp.value) Then sTmp = sTmp + "checked "
sTmp = sTmp + "onClick='Call UpdateProperty(""" + oProp.Name +
""", id" + oProp.Name + ".checked)' "
sTmp = sTmp + "> " + ResourceDescription(oProp.Name) +
"</td></tr>"
End If
Next
DisplayResources= sTmp
End Function

Sub UpdateProperty(sName,sVal)
Dim oProp
For Each oProp In cmiThis.Properties
If oProp.Name = sName Then
oProp.Value = CBool(sVal)
End If
Next
End Sub


Function ResourceDescription(sName)
Dim oRes
ResourceDescription= "Unknown"
For Each oRes In cmiThis.Resources
If oRes.DisplayName = sName Then
ResourceDescription= oRes.Description
End If
Next
End Function

document.write(DisplayResources ())
</SCRIPT>
</td>
</tr>
</table>
<hr>
</BODY>
</HTML>

=================

next the VBS post

Thijs
 
The VB-script. Very simple just go through the available properties. If the
name starts with "res" set the resource with the same name to enabled or
disabled.

===================

Sub cmiOnBeginBuild(dwFlags)
Dim oProp, oRes
For Each oProp in cmiThis.Properties
If Left(oProp.Name,3) = "res" Then
For Each oRes in cmiThis.Resources
If oRes.DisplayName = oProp.Name Then
oRes.Disabled = Not CBool(oProp.Value)
End If
Next
End If
Next
End Sub

=======================


Another VBS example, my very own AutoLogon. Why, "Allowing auto-resolve to
add Windows Logon to a runtime causes the automatic logon default username to
be overwritten." as described at
http://msdn.microsoft.com/library/d...icrosoftWindowsXPEmbeddedWithServicePack2.asp
Took me a long time to get the reason for my problems. But anyway, I just
added the following script to a custom user component prototyped on "User
Account".

=====================

Sub cmiOnEndBuild(dwFlags)
Dim oProp, bAuto, sName, sPass
'Read AutoLogon, UserName and UserPassword properties
For Each oProp In cmiThis.Properties
If oProp.Name = "ncpAutoLogon" Then
bAuto = CBool(oProp.Value)
ElseIf oProp.Name = "cmiUserPassword" Then
sPass = CStr(oProp.Value)
ElseIf oProp.Name = "cmiUserName" Then
sName = CStr(oProp.Value)
End If
Next
'Write data to registry
If bAuto Then
oPL.TargetRegEdit cRegOpWrite, cRegCondAlways, cmiREG_SZ,
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon",
"DefaultUserName", sName, cmiString
oPL.TargetRegEdit cRegOpWrite, cRegCondAlways, cmiREG_SZ,
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon",
"AltDefaultUserName", sName, cmiString
oPL.TargetRegEdit cRegOpWrite, cRegCondAlways, cmiREG_SZ,
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon",
"DefaultPassword", sPass, cmiString
oPL.TargetRegEdit cRegOpWrite, cRegCondAlways, cmiREG_SZ,
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon",
"AutoAdminLogon", "1", cmiString
End If
End Sub

========================

I use the properties I inhereted from "User Account", for username and
password
and my own ncpAutoLogon property to dicide. The ncpAutoLogon property is set
though the HTML below.

==========================

<HTML>
<HEAD>
<STYLE TYPE="text/css">
<!--

BODY { font: normal 8pt Tahoma; background-color: #FFFFFF; }
P { font: normal 8pt Tahoma; }
TABLE { font: normal 8pt Tahoma; text-align: left; padding: 2px; }
LABEL { font: bold 8pt Tahoma; text-align: left; padding: 2px; }
TD { font: normal 8pt Tahoma; text-align: left; padding: 2px; }
TR { font: normal 8pt Tahoma; text-align: left; padding: 2px; }

-->
</STYLE>
</HEAD>
<BODY>
<hr>
<table>
<caption> </caption>
<tr><td><label for="idCWA">AutoLogon:</label></td></tr>
<tr>
<td>
<SCRIPT type="text/vbscript">
Option Explicit
Dim cmiThis : Set cmiThis = window.external.Instance

Function DisplayCheck()
Dim oProp, sTmp
Set oProp = cmiThis.Properties("ncpAutoLogon")
sTmp = "<tr><td><input type=checkbox "
sTmp = sTmp + "name='id" + oProp.Name + "' "
If CBool(oProp.value) Then sTmp = sTmp + "checked "
sTmp = sTmp + "onClick='Call UpdateProperty(""" + oProp.Name + """,
id" + oProp.Name + ".checked)' "
sTmp = sTmp + "> Enable AutoLogon for this user</td></tr>"
DisplayCheck = sTmp
End Function

Sub UpdateProperty(sName,sVal)
Dim oProp
For Each oProp In cmiThis.Properties
If oProp.Name = sName Then
oProp.Value = CBool(sVal)
End If
Next
End Sub

document.write(DisplayCheck())
</SCRIPT>
</td>
</tr>
</table>
<hr>
</BODY>
</HTML>

===============================

Hope this helps.
 
Yeah, it's not documented at all, sorry. We hadn't anticipated that back in
the day <grin>

You can open an SLD we ship in the service pack sld or in QFEs in component
designer. And if there's DHTML capability you will see in the main pane for
CD that there is an HTM and VBS file embedded. You can export those from CD
and then open in your editor to see how to access some of the functions.
Check out the Windows Firewall component for an excellent example. Internet
Explorer and Enhanced Write Filter are two good ones also.

Good luck.
 
CMI stands for Configuration Management Interface.
This scripting (VBS) is used to change certain aspects of an embedded
configuration, much like you could do via the user interface of the TD.
You can enable/diable or change components, or edit the registry of your
target for example.
 
Back
Top