ASP learning: remotely Register Your Own Components

Source: Internet
Author: User

There are many advantages to using asp programs as dll. However, this dll must be registered before it can be called in asp. If it is your own server, it is fine, but if it is a rented virtual server, it cannot be used. How can we register our dll on a remote host? Use Shell on the server.

Let's first upload our dll file to the server through ftp or http, and then make an asp program, call WScript. Shell to execute the regsvr32 command:
Set oShell = CreateObject ("WScript. Shell ")
OShell. Run "c: \ WINNT \ system32 \ regsvr32.exe/s d: \ xxx. dll", 0, False

Of course, if the server security of the other party is very good, this Code may not be available, but no matter what the problem is, it is also good to learn. Here we should also remind those who are renting a space, does your server limit the use of WScript. shell Permission?

The complete code is as follows. Save it as. asp for use:

<% 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, fr1_hod)
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) 'lists all dll and ocx files through fso
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 = fr1_hod 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
%>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.