There are many benefits to making an ASP program a DLL, but one thing is that the DLL must be registered to be invoked in ASP. If it's your own server, that's fine, but if you're renting a virtual server, you won't be able to use it.
How do I register our DLL on a remote host? Using shell!!! on the server side
Let's first upload our DLL file to the server via FTP or HTTP, 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 other side of the server security is very good, this code may not be used, but anyway, learning is also good,:
Here also to remind those who rent space friends, your server has limited the use of Wscript.Shell permissions? It's better to be careful.
The complete code is as follows, saved as. asp to 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 (+) & ">")
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 () & "Frmdllpath" & Chr (+) & ">")
Call Getalldlls (Orootdir)
Echob ("</SELECT>")
Buildoptions
End Sub
Sub getalldlls (oparentfolder) ' Lists all DLLs and OCX files through the 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 () & Ofile.path & Chr (+) & ">" _
& 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 () & Ofile.path & Chr (+) & ">" _
& Ofile.name & "</Option>")
End IF
Next
Call Getalldlls (Ofolder)
Next
On Error GoTo 0
End Sub
Sub Register (strFilePath, Regmethod)
Dim the