ASP學(xué)習(xí):遠(yuǎn)程注冊自己的組件

字號:

讓我們先將自己的dll文件通過ftp或http上傳到服務(wù)器上,然后作一個asp程序,調(diào)用WScript.Shell來 執(zhí)行regsvr32命令:
    Set oShell = CreateObject ("WScript.Shell")
    oShell.Run "c:WINNTsystem32regsvr32.exe /s d:xxx.dll", 0, False
    當(dāng)然如果對方的服務(wù)器安全搞的很好的話,這個代碼也許就不能用了,但不管怎么樣,學(xué)習(xí)一下 也是好的,在這里也要提醒那些出租空間的朋友,你的服務(wù)器是否限制了使用WScript.Shell的權(quán)限?
    完整代碼如下,保存為.asp即可使用:
    <% 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")
    %>
    
    
    Regsvr32.asp
    
    
    
    

    
    
    
    
    

    

    Regsvr Functions
    Insert Path to DLL Directory
    
    
    <%
    IF Request.Form("btnFileList") <> "" OR btnREG <> "" Then
    Set RegisterFiles = New clsRegister
    RegisterFiles.EchoB("Select File")
    Call RegisterFiles.init(frmFolderPath)
    RegisterFiles.EchoB("
    ")
    IF Request.Form("btnREG") <> "" Then
    Call RegisterFiles.Register(frmFilePath, frmMethod)
    End IF
    Set RegisterFiles = Nothing
    End IF
    %>
    

    

    

    
    
    <%
    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("Folder ( " & strRoot & " ) Not Found.")
    Exit Sub
    End IF
    setRoot = oRootDir
    Echo("")
    BuildOptions
    End Sub
    Sub getAllDlls(oParentFolder)  ’通過fso列舉所有的dll和ocx文件
    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("")
    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("")
    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:WINNTsystem32regsvr32.exe /s " & strFile, 0, False
    exitcode = oShell.Run("c:WINNTsystem32regsvr32.exe /s " & strFile, 0, False)
    EchoB("regsvr32.exe exitcode = " & exitcode)
    Else ’unRegister
    oShell.Run "c:WINNTsystem32regsvr32.exe /u/s " & strFile, 0, False
    exitcode = oShell.Run("c:WINNTsystem32regsvr32.exe /u/s " & strFile, 0, False)
    EchoB("regsvr32.exe exitcode = " & exitcode)
    End IF
    Cleanup oShell
    End Sub
    Sub BuildOptions
    EchoB("Register: ")
    EchoB("unRegister: ")
    End Sub
    Function Echo(str)
    Echo = Response.Write(str & vbCrLf)
    End Function
    Function EchoB(str)
    EchoB = Response.Write(str & "
    " & 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
    %>