-----------------------------------------------root1---------------------------------------
*******************************************************************************************
*使用本class可以管理并在asp页里面注册你的dll
*本class在win 2k上测试通过
*注:使用本class需要先建立一个xml文件。文件如下.打开记事本将如下3行存为*.xml文件
*
* <?xml version="1.0" encoding="gb2312" standalone="yes"?>
* <dll列表>
* </dll列表>
*
*------------------------------------------------------------------------------------------
*范例:
* dim objregsvr32
* set objregsvr32 = new regsvr32
* with objregsvr32
* if .loadxml("../mydll.xml") then
* call response.write("xml文件加载错误")
* set objregsvr32 = nothing
* response.end
* end if
* select case .addnode("f:\web\cw31072\dll\test\myclass.dll" , true) '添加新条目并注册dll
* case 1
* call response.write("条目已经添加进xml文件!并成功注册dll啦!")
* case 0
* call response.write("条目已经添加进xml文件!但注册dll时失败!")
* case -1
* call response.write("xml文件里已经有该条目!该dll也已经注册的了!")
* end select
* ..........................
* end with
*
* '本class非常简单,里面还有些方法,我就不举例了,看看就知道了。日后你可以打开
* '该xml文件看你曾经注册过和待注册的dll列表。
* 'xml文件里每个条目如下:<dll 是否已经注册="1">f:\web\cw31072\dll\test\myclass.dll</dll>
* 'f:\web\cw31072\dll\test\myclass.dll就是你dll文件的路径
* '是否已经注册="1"就是该dll已经注册过,=“0”就是还没有注册呢!
*******************************************************************************************
class regsvr32
private s_objxml
private s_objnoderoot
private s_strxmlpath
private s_strattributename
'------------------------------------
'目的: 加载dll配置xml文件
'参数: xml文件地址
'返回: 加载失败就返回true
'------------------------------------
public function loadxml(strpath)
set s_objxml = createobject("msxml2.domdocument")
s_objxml.async = false
s_objxml.load(strpath)
if s_objxml.parseerror.errorcode <> 0 then
set s_objxml = nothing
loadxml = true
exit function
end if
set s_objnoderoot = s_objxml.documentelement
s_strxmlpath = strpath
s_strattributename = "是否已经注册"
end function
'---------------------------------------------
'目的: 添加一个dll项目
'参数: strpath: dll文件地址
' blnreg: 添加后是否将其注册
'返回: 如果要求添加后注册,注册成功就返回1,注册失败返回0,已经有该项目并注过册就返回-1
'---------------------------------------------
public function addnode(strpath , blnreg)
dim objnewnode
dim strstart
dim objnode
strstart = "0"
set objnode = selectnode(strpath)
if objnode is nothing then
if reg(strpath , true) then
strstart = "1"
addnode = true
else
addnode = false
end if
set objnewnode = s_objxml.createelement("dll")
call objnewnode.setattribute(s_strattributename , strstart)
objnewnode.text = strpath
call s_objnoderoot.appendchild(objnewnode)
call s_objxml.save(s_strxmlpath)
else
if blnreg then
if objnode.attributes.getnameditem(s_strattributename).nodevalue = "1" then
addnode = true
else
if reg(strpath , true) then
objnode.attributes.getnameditem(s_strattributename).nodevalue = "1"
call s_objxml.save(s_strxmlpath)
else
addnode = false
end if
end if
else
addnode = false
end if
end if
end function
'----------------------------------------
'目的: 删除所有已经注册,或者没注册的节点
'参数: blnstart: 0=未注册的,1=已经注册的
'返回: 执行了删除操作就返回true,否则返回false
'----------------------------------------
public function reallnode(byval blnstart)
dim objnode
dim blnischange
blnstart = cstr(blnstart)
for each objnode in s_objnoderoot.childnodes
if objnode.attributes.getnameditem(s_strattributename).nodevalue = blnstart then
call s_objnoderoot.removechild(objnode)
blnischange = true
end if
next
if blnischange then
reallnode = true
call s_objxml.save(s_strxmlpath)
else
reallnode = false
end if
end function
'-----------------------------------------
'目的: 删除某一个节点
'参数: 节点内容
'返回: 找不到节点就返回true
'-----------------------------------------
public function renode(strpath)
dim objnode
set objnode = selectnode(strpath)
if objnode is nothing then
renode = true
else
call s_objnoderoot.removechild(objnode)
call s_objxml.save(s_strxmlpath)
end if
end function
'-----------------------------------------
'目的: 寻找某个节点
'参数: strpath: 节点内容
'返回: 找到就返回该节点,找不到就返回nothing
'-----------------------------------------
private function selectnode(byval strpath)
dim objnode
strpath = ucase(strpath)
for each objnode in s_objnoderoot.childnodes
if ucase(objnode.childnodes.item(0).nodevalue) = strpath then
set selectnode = objnode
exit function
end if
next
set selectnode = nothing
end function
'--------------------------------------------
'目的: 查看dll文件列表里某个文件注册状态
'参数: 该文件路径
'返回: 1=已经注册
' 0=未注册
' -1=找不到该文件
'--------------------------------------------
public function checkdll(strpath)
dim objnode
set objnode = selectnode(strpath)
if objnode is nothing then
checkdll = -1
else
checkdll = cint(objnode.attributes.getnameditem(s_strattributename).nodevalue)
end if
end function
'--------------------------------------
'目的: 将所有未注册的dll注册
'返回: 如果有某个dll注册失败就返回true
'--------------------------------------
public function regallnode()
dim objnode
for each objnode in s_objnoderoot.childnodes
if objnode.attributes.getnameditem(s_strattributename).nodevalue = "0" then
if reg(objnode.childnodes.item(0).nodevalue , true) then
objnode.attributes.getnameditem(s_strattributename).nodevalue = 1
else
regallnode = true
end if
end if
next
end function
'-----------------------------------------
'目的: 注册dll
'参数: strpath: 要注册dll文件路径
' blnloding: 是否等待注册完成才继续执行程序
'返回: 如果blnloging=true,注册成功就返回true
'-----------------------------------------
private function reg(strpath , blnloding)
dim objshell
set objshell = createobject("wscript.shell")
if objshell.run("regsvr32.exe /s " & strpath , , blnloding) = 0 then
reg = true
end if
set objshell = nothing
end function
end class