'------------------------------------ '目的: 加載DLL配置xml文件 '參數(shù): 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 = "是否已經(jīng)注冊" end function
'--------------------------------------------- '目的: 添加一個DLL項目 '參數(shù): strPath: DLL文件地址 ' blnReg: 添加后是否將其注冊 '返回: 如果要求添加后注冊,注冊成功就返回1,注冊失敗返回0,已經(jīng)有該項目并注過冊就返回-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
'---------------------------------------- '目的: 刪除所有已經(jīng)注冊,或者沒注冊的節(jié)點 '參數(shù): blnStart: 0=未注冊的,1=已經(jīng)注冊的 '返回: 執(zhí)行了刪除操作就返回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
'----------------------------------------- '目的: 刪除某一個節(jié)點 '參數(shù): 節(jié)點內(nèi)容 '返回: 找不到節(jié)點就返回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
'----------------------------------------- '目的: 尋找某個節(jié)點 '參數(shù): strPath: 節(jié)點內(nèi)容 '返回: 找到就返回該節(jié)點,找不到就返回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文件列表里某個文件注冊狀態(tài) '參數(shù): 該文件路徑 '返回: 1=已經(jīng)注冊 ' 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 '參數(shù): strPath: 要注冊Dll文件路徑 ' blnLoding: 是否等待注冊完成才繼續(xù)執(zhí)行程序 '返回: 如果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