好久没有更新了.今天发现了一个小东西,怕以后忘掉,特此记录一下.
本来想给自己的字符串批量替换工具 添加脚本支持.添加引用的时候发现了Scriptlet. 也就听说过java有applet serverlet 这个windows 下面的 scriptlet是什么东西.说不定能拿来为我所用.
查阅了一些资料.大体明白了.主要是用于 IIS的.
按照微软示例的解释.我们想要给asp提供支持.通常都是自己用vb vc写com对象.比如activeDLL 之类.用了scriptlet,我们可以用脚本写com对象,给asp提供支持.或者任何其他用com的东西.而且也要自己注册classid之类的东西(vb6运行的时候自动注册,或者可以regsvr32注册,但是这个东西好像....)
看起来,还是我们调用脚本.而且还多了一层.程序用起来的时候还要添加引用.不如直接调用方便.很鸡肋的感觉.也许是为了方便服务器管理员??他们用脚本何必到COM这一层?别人谁会用你的脚本?自己用为何不直接创建activedll?只能理解为,这个东西是可以随时编辑不需要像dll更新那么麻烦.(但是我还是不能理解,固定化的exe就算调用变化的东西也可以直接用脚本不需要经过com啊).
算了.直接看微软的示例吧
Title
概要
Microsoft Windows 脚本组件允许开发人员编写 COM 组件, 称为 Scriptlets Scriptlets , 用 VBScript 或 JavaScript 等语言。 然后从任何 COM 兼容编程环境, 如 MicrosoftVisualC++、 VisualBasic 或 Active Server 页 (ASP) 调用这些组件。
Title
| 1. |
复制以下代码并保存为 " Example.sct " 桌面上:
<SCRIPTLET>
<REGISTRATION
Description="DHTML Button Scriplet"
ProgID="DHTML.Button.Scriptlet"
Version="1.0" >
</REGISTRATION>
<IMPLEMENTS ID="Automation" TYPE="Automation">
<METHOD NAME="CreateButton">
<PARAMETER NAME="txt"/>
<PARAMETER NAME="url"/>
<PARAMETER NAME="fore"/>
<PARAMETER NAME="back"/>
<PARAMETER NAME="glow"/>
<PARAMETER NAME="width"/>
</METHOD>
</IMPLEMENTS>
<SCRIPT LANGUAGE="VBScript">
Option Explicit
Function CreateButton(txt,url,fore,back,glow,width)
Dim strNormal
Dim strGlow
strNormal = "this.style.background='" & back & "';"
strGlow = "this.style.background='" & glow & "';"
CreateButton = vbCrLf & "<table border=""0""
cellpadding=""5"">" & vbCrLf
CreateButton = CreateButton & "<tr><td align=""center"""
CreateButton = CreateButton & " language=""JavaScript""" &
vbCrLf
If width <> "" Then
CreateButton = CreateButton & " width=""" & width & """"
End If
CreateButton = CreateButton & " style=""background:""" & back
& ";"
CreateButton = CreateButton & "color:" & fore & ";""" &
vbCrLf
CreateButton = CreateButton & " onMouseover=""" & strGlow &
"""" & vbCrLf
CreateButton = CreateButton & " onMouseout=""" & strNormal &
""">" & vbCrLf
CreateButton = CreateButton & "<a href=""" & url & """"
CreateButton = CreateButton & " style=""text-decoration:none;"""
CreateButton = CreateButton & "color:" & fore & "";"">" &
vbCrLf
CreateButton = CreateButton & txt & "</a></td></tr>" &
vbCrLf
CreateButton = CreateButton & "</table>" & vbCrLf
End Function
</SCRIPT>
</SCRIPTLET>
备注:
| |
| • |
注册 节中 ProgID 字段引用 ID scriptlet 的类。 |
| • |
注册 scriptlet, 后注册表在以下位置中创建项对于类 ProgID 和 CLSID:
HKEY_CLASSES_ROOT\DHTML.Button.Scriptlet
HKEY_CLASSES_ROOT\DHTML.Button.Scriptlet\CLSID
|
| • |
使用 CLSID 默认值, 可获取类 GUID, 可用于生成路径以下列两项:
HKEY_CLASSES_ROOT\CLSID\{class GUID goes here}\InprocServer32
HKEY_CLASSES_ROOT\CLSID\{class GUID goes here}\ScriptletURL
|
| • |
这些两项很中获取下列疑难解答信息尤其有用:
InprocServer 32 = 处理程序 DLL (例如 Scrobj.dll): 路径 ScriptletURL = scriptlet 路径:
|
|
|
| 2. |
右击 scriptlet 选择 注册 , 并再单击对于确认对话框 确定 。 |
| 3. |
在 IIS 计算机上保存以下 ASP 代码作为 " Example.asp " Web 文件夹中: 与启用 脚本访问
<%@LANGUAGE="VBSCRIPT"%>
<% Option Explicit %>
<html>
<body>
<%
Dim objButton
Set objButton = Server.CreateObject("DHTML.Button.Scriptlet")
Response.Write objButton.CreateButton("Back to
Home","/","white","black","#0000ff","100")
Response.Write
objButton.CreateButton("Microsoft","http://www.microsoft.com","#ff
ff00","magenta","#33cc33","100")
Response.Write
objButton.CreateButton("MSDN","http://msdn.microsoft.com","black",
"red","brown","100")
%>
</body>
</html>
|
| 4. |
当浏览示例页, 应看到三 DHTML 悬停按钮。 |