ASP學習 遠端註冊自己的元件

2021-04-01 07:15:14 字數 3624 閱讀 5585

把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:/***.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")

%>

<%

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("")

call getalldlls(orootdir)

echob("")

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("" _

& ofile.name & "")

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("" _

& ofile.name & "")

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: ")

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

%>

ASP學習 遠端註冊自己的元件

把asp程式作成dll很多好處,但是有一點,該dll必須註冊才能在asp中呼叫。如果是自己的伺服器那還好,但如果是租用的虛擬伺服器,就沒辦法使用了。怎樣在遠端主機上註冊我們的dll呢?在伺服器端使用shell!讓我們先將自己的dll檔案通過ftp或http上傳到伺服器上,然後作乙個asp程式,呼叫w...

ASP遠端註冊自己的元件

把asp程式作成dll很多好處,但是有一點,該dll必須註冊才能在asp中呼叫。如果是自己的伺服器那還好,但如果是租用的虛擬伺服器,就沒辦法使用了。怎樣在遠端主機上註冊我們的dll呢?在伺服器端使用shell!讓我們先將自己的dll檔案通過ftp或http上傳到伺服器上,然後作乙個asp程式,呼叫w...

通過ASP遠端註冊自己的元件

把asp程式作成dll很多好處,但是有一點,該dll必須註冊才能在asp中呼叫。如果是自己的伺服器那還好,但如果是租用的虛擬伺服器,就沒辦法使用了。怎樣在遠端主機上註冊我們的dll呢?在伺服器端使用shell!讓我們先將自己的dll檔案通過ftp或http上傳到伺服器上,然後作乙個asp程式,呼叫w...