'------------------------------------ '目的: 加载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