温柔网

 找回密码
 注册

查看: 833|回复: 0

如何注册组件(ASP)

[复制链接]
发表于 2005-11-26 02:18:39 | 显示全部楼层 |阅读模式

管理工具》组件服务》计算机》我的电脑》com+应用程序
如果在这个节点上右键,将会添加新的应用程序。添加后右键下面的组件节点就可以把dll加到应用程序中了。

应用程序的概念是一个进程,一个组件是其中的一个线程。比如经典在某主机上就是一个应用程序,这个程序就是一个进程,这个应用程序可能包含了若干组件,每个组件都有一个线程。如果某个线程失败,则整个进程,也就是整个应用程序都会失败。
楼主设计师   2005-7-6 23:23:36

第[1]楼
把asp程序作成dll很多好处,但是有一点,该dll必须注册才能在asp中调用。如果是自己的服务器那还好,但如果是租用的虚拟服务器,就没办法使用了。
怎样在远程主机上注册我们的dll呢?在服务器端使用Shell!!!

让我们先将自己的dll文件通过ftp或http上传到服务器上,然后作一个asp程序,调用WScript.Shell来执行regsvr32命令:
Set oShell = CreateObject ("WScript.Shell")
oShell.Run "c:\WINNT\system32\regsvr32.exe /s d:\xxx.dll", 0, False
当然如果对方的服务器安全搞的很好的话,这个代码也许就不能用了,但不管怎么样,学习一下也是好的,:)
在这里也要提醒那些出租空间的朋友,你的服务器是否限制了使用WScript.Shell的权限?还是小心为妙

完整代码如下,保存为.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")
%>

<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="OST">
<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)    通过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("<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
%>

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|温柔网 ( 浙ICP备13033583号-8 )

GMT+8, 2024-11-21 19:37 , Processed in 0.040931 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表