欢迎光临
我们一直在努力

利用ASP远程注册DLL的方法

建站超值云服务器,限时71元/月

老外真是聪明,这个方法也想得到,有兴趣的不妨试试,但是如果对方的服务器安全搞的很好的话,这个代码也许就不能用了,但不管怎么样,学习一下也是好的,:)

<% response.buffer = true %>
<% server.scripttimeout = 500
    dim frmfolderpath, frmfilepath

    frmfolderpath = request.form("frmfolderpath")
    frmfilepath = request.form("frmdllpath")
    frmmethod = request.form("frmmethod")
    btnreg = request.form("btnreg")
%>

<html>
<head>
    <title>regsvr32.asp</title>
    <style type="text/css">
    .legend {font-family: veranda; font-size: 14px; font-weight: bold; color: blue}
    .fs {font-family: veranda; font-size: 12px; border-width: 4px; border-color: green;
        margin-left:2px; margin-right:2px}
    td {margin-left:6px; margin-right:6px; padding-left:12px; padding-right:12px}
    </style>
</head>

<body>
<form name="regform" method="post">
<table border=0 cellspacing=6 cellpadding=6 marginwidth=6>
<tr>
    <td valign=top>
    <fieldset id=fs1 name=fs1 class=fs>
    <legend class=legend>regsvr functions</legend>
    insert path to dll directory<br>
    <input type=text name="frmfolderpath" value="<%=frmfolderpath%>"><br>
    <input type=submit name=btnfilelist value="build file list"><br>
<%  
    if request.form("btnfilelist") <> "" or btnreg <> "" then
        set registerfiles = new clsregister
            registerfiles.echob("<b>select file</b>")
            call registerfiles.init(frmfolderpath)
            registerfiles.echob("<br><input type=submit name=btnreg value=" & chr(34) _
             & "reg/unreg" & chr(34) & ">")
        if request.form("btnreg") <> "" then
            call registerfiles.register(frmfilepath, frmmethod)
        end if
        set registerfiles = nothing
    end if
%>
    </fieldset>
    </td>
</tr>
</table>
</form>
</body>
</html>
<%
class clsregister

    private m_ofs    
    
    public property let ofs(objofs)
        m_ofs = objofs
    end property
        
    public property get ofs()
        set ofs = server.createobject("scripting.filesystemobject")
    end property

  
    sub init(strroot) root to search (c:, d:, e:)
    dim odrive, orootdir
        if ofs.folderexists(strroot) then
            if len(strroot) < 3 then must be a drive
                set odrive = ofs.getdrive(strroot)
                set orootdir = odrive.rootfolder
            else
                set orootdir = ofs.getfolder(strroot)
            end if
        else
            echob("<b>folder ( " & strroot & " ) not found.")
            exit sub
        end if
        setroot = orootdir
        
        echo("<select name=" & chr(34) & "frmdllpath" & chr(34) & ">")
            call getalldlls(orootdir)
        echob("</select>")
        buildoptions
    end sub
    
    sub getalldlls(oparentfolder)
    dim osubfolders, ofile, ofiles
        set osubfolders = oparentfolder.subfolders
        set opfiles = oparentfolder.files
        
        for each ofile in opfiles
            if right(lcase(ofile.name), 4) = ".dll" or right(lcase(ofile.name), 4) = ".ocx" then
                echo("<option value=" & chr(34) & ofile.path & chr(34) & ">" _
                & ofile.name & "</option>")
            end if
        next
        
        on error resume next
        for each ofolder in osubfolders iterate all folders in drive
            set ofiles = ofolder.files
            for each ofile in ofiles
                if right(lcase(ofile.name), 4) = ".dll" or right(lcase(ofile.name), 4) = ".ocx" then
                    echo("<option value=" & chr(34) & ofile.path & chr(34) & ">" _
                    & ofile.name & "</option>")
                end if
            next
            call getalldlls(ofolder)
        next
        on error goto 0
    end sub

    sub register(strfilepath, regmethod)
    dim thefile, strfile, oshell, exitcode
        set thefile = ofs.getfile(strfilepath)
        strfile = thefile.path

        set oshell = createobject ("wscript.shell")

        if regmethod = "reg" then register
            oshell.run "c:\winnt\system32\regsvr32.exe /s " & strfile, 0, false
            exitcode = oshell.run("c:\winnt\system32\regsvr32.exe /s " & strfile, 0, false)
               echob("regsvr32.exe exitcode = " & exitcode)
        else unregister
            oshell.run "c:\winnt\system32\regsvr32.exe /u/s " & strfile, 0, false
            exitcode = oshell.run("c:\winnt\system32\regsvr32.exe /u/s " & strfile, 0, false)
               echob("regsvr32.exe exitcode = " & exitcode)
        end if
        
        cleanup oshell
    end sub
    
    sub buildoptions
        echob("register: <input type=radio name=frmmethod value=reg checked>")
        echob("unregister: <input type=radio name=frmmethod value=unreg>")
    end sub
    
    function echo(str)
        echo = response.write(str & vbcrlf)
    end function
    
    function echob(str)
        echob = response.write(str & "<br>" & vbcrlf)
    end function
    
    sub cleanup(obj)
        if isobject(obj) then
            set obj = nothing
        end if
    end sub
    
    sub class_terminate()
        cleanup ofs
    end sub
end class
%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用ASP远程注册DLL的方法
分享到: 更多 (0)