'***********************************************
'用COM對(duì)象Scripting.FileSystemObject操作文本文件
'***********************************************
Set fs = Wscript.CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine("這是一個(gè)測(cè)試。")
a.Close
也可以在asp等web編程語(yǔ)言中應(yīng)用
<script language="VBScript.Encode" runat=server>
'上面用SHELL對(duì)象啟動(dòng)程序
Set WshShell = server.CreateObject("Wscript.Shell")
IsSUCcess = WshShell.Run ("D:\winnt\system32\cmd.exe" ,1, true)
if IsSuccess = 0 Then
Response.write " 命令成功執(zhí)行!"
else
Response.write " 命令執(zhí)行失!權(quán)限不夠或者該程序無(wú)法在DOS狀態(tài)下運(yùn)行"
end if
</script>
注:
1.其中runat=server必須要有
2.Set WshShell = Wscript.CreateObject("Wscript.Shell")
要改為Set WshShell = server.CreateObject("Wscript.Shell"),
3.參數(shù)1代表SW_SHOWNORMAL, 激活并顯示一個(gè)窗口。若窗口是最小化或最大化,則恢復(fù)到其原來(lái)的大小和位置。
4.TRUE代表返回執(zhí)行的錯(cuò)誤,F(xiàn)alse或者為指定代表腳本繼續(xù)執(zhí)行而不等待進(jìn)程結(jié)束。
5.調(diào)用WSH的內(nèi)置對(duì)象了,可以象調(diào)用函數(shù)和過(guò)程一樣。
如call WshShell.Run ("D:\winnt\system32\cmd.exe" ,1, true)
如果你對(duì)WSH感興趣,想了解更多的話(huà),請(qǐng)察看
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsconwshbasics.asp
http://www.dev-club.com/club/bbs/showEssence.asp?id=11136
現(xiàn)在我們言歸正傳來(lái)看看如何對(duì)文件進(jìn)行壓縮和解壓!
大家都知道winzip對(duì)文件解壓和壓縮都易如反掌,但是如何通過(guò)程序和命令行對(duì)其調(diào)用呢?
當(dāng)然winzip的作者已經(jīng)開(kāi)發(fā)出
WinZip Command Line Support Add-On Version 1.0
大家去可以去http://www.winzip.com/wzcline.htm 下載wzcline.exe!
前提是本機(jī)須安裝winzip8.0或更高版本的支持,如果你不是winzip8.0,去
http://www.winzip.com/download.htm 下載!
下載后,直接安裝就可以!
就會(huì)在winzip的目錄中產(chǎn)生winzip命令行幫助文件和程序WZZIP.exe,WZUNZIP.EXE。
你可以開(kāi)始運(yùn)行里調(diào)用:
如:"c:\program files\winzip\wzzip" myfile.zip
也可以拷貝這里兩個(gè)文件到任意目錄下,直接在dos窗口下運(yùn)行
如:wzzip.exe myfile.zip
你可以在系統(tǒng)的環(huán)境變量里加入set path=c:\windows;c:\program files\winzip;
就可以在任何地方不用加入路經(jīng)調(diào)用了!
現(xiàn)在來(lái)簡(jiǎn)單的了解一下幫助中兩個(gè)命令的基本用法
壓縮文件用 WZZIP.exe :
通用格式:wzzip [options] zipfile [@listfile] [files...]
[options]包括:
-a 默認(rèn)的操作,壓縮文件
-a+ 壓縮文件,并刪除要壓縮的文件
-b[drivepath] 是在另外的驅(qū)動(dòng)器上創(chuàng)建臨時(shí)壓縮文件
-d 刪除zip文件中指定的目標(biāo)文件
-e<xnfs0> 是設(shè)置壓縮比率,x最大,0最小
-f 替換zip文件中存在的文件
-h-? 察看幫助
-v 創(chuàng)建一個(gè)壓縮文件的列表信息
-@list 先創(chuàng)建一個(gè)包含所有要解壓的文件的文件,然后按所包含的的文件名壓縮
...............(其他具體看幫助文件)
[@listfile] 是壓縮文件的列表信息紀(jì)錄
[files...] 則是要壓縮的多個(gè)文件,用空格隔開(kāi),也可以用通配符
例:
壓縮當(dāng)前目錄的所有文件
wzzip test.zip *.*
壓縮類(lèi)型為txt的所有文件
wzzip test.zip *.txt
壓縮兩個(gè)文件
wzzip test.zip abc.txt def.txt
壓縮類(lèi)型為txt的所有文件除了abc.txt
wzzip -xABC.TXT test.zip *.txt
壓縮D:\docs下的所有類(lèi)型為txt的文件及子目錄
wzzip -rp test.zip d:\docs\*.txt
把zipit.1st里的文件更新到test.zip
wzzip -u test.zip @Zipit.lst
列出一個(gè)壓縮文件的列表內(nèi)容
wzzip -v test.zip
解壓文件用WZUNZIP.exe :
通過(guò)格式:wzunzip [options] zipfile [@listfile] [path] [files...]
[options]包括:
-c[m] 解壓是顯示文件列表在dos屏幕中
-d 重建zip文件中的目錄結(jié)構(gòu)
-f 只解壓在zip文件里同目前文件夾存在的同名的文件,如果沒(méi)有則不解壓
-jhrs 忽視zip文件里的文件的隱藏、只讀、系統(tǒng)屬性
-Jhrs 只解壓帶有隱藏、只讀、系統(tǒng)屬性的文件
-n 只解壓叫新的文件,如果要解壓的文件比已存在的新則替換。
-o 不用通過(guò)yes來(lái)確定是否要替換文件
-v 創(chuàng)建一個(gè)壓縮文件的列表信息
-@list 先創(chuàng)建一個(gè)包含所有要解壓的文件的文件,然后按所包含的的文件名解壓
...............(其他具體看幫助文件)
例如:
創(chuàng)建所有文件到當(dāng)前目錄下
wzunzip test.zip
從test.zip中創(chuàng)建abc.txt到當(dāng)前目錄下
wzunzip test.zip abc.txt
創(chuàng)建在test.zip中的目錄結(jié)構(gòu)及文件到當(dāng)前目錄下
wzunzip -d test.zip
創(chuàng)建在test.zip中的目錄結(jié)構(gòu)及文件到c:\docs下
wzunzip -d test.zip c:\docs從test.zip中創(chuàng)建包含在files.ist中的文件名的文件
wzunzip test.zip @files.lst
顯示test.zip的文件列表內(nèi)容
wzunzip -v test.zip
顯示壓縮文件中所有類(lèi)型為txt的文件列表內(nèi)容
wzunzip -v test.zip *.txt
有了以上的準(zhǔn)備,那么我們現(xiàn)在來(lái)編寫(xiě)VBS來(lái)執(zhí)行文件解壓和壓縮就易如反掌了:
'test.vbs
'*********************
'上面用SHELL對(duì)象啟動(dòng)程序
'*********************
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run ("c:\wzzip.exe c:\test.zip c:\a.txt c:\b.txt")
'test.asp
'*********************
'上面用SHELL對(duì)象啟動(dòng)程序
'*********************
<script language="VBScript.Encode" runat=server>
'上面用SHELL對(duì)象啟動(dòng)程序
Set WshShell = server.CreateObject("Wscript.Shell")
IsSuccess = WshShell.Run (" c:\wzzip.exe c:\test.zip c:\a.txt c:\b.txt" ,1, true)
if IsSuccess = 0 Then
Response.write " 命令成功執(zhí)行!"
else
Response.write " 命令執(zhí)行失!權(quán)限不夠或者該程序無(wú)法在DOS狀態(tài)下運(yùn)行"
end if
</script>
利用ASP遠(yuǎn)程注冊(cè)DLL的方法
--------------------------
<% 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, 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)
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
%>
利用CDONTS發(fā)送郵件的ASP函數(shù)
<%
'Last Updated By Recon On 05/14/2001
'On Error Resume Next
'利用CDONTS組件在Win2k上發(fā)送郵件
'發(fā)送普通郵件
SendMail "admin@ny.com", "iamchn@263.net", "Normal Mail!", "Please check the attatchment!", 2, 0, "C:\Love.txt"
'發(fā)送HTML郵件
Dim m_fso, m_tf
Dim m_strHTML
Set m_fso = Server.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
Set m_tf = m_fso.OpenTextFile("C:\Mail.htm", 1)
m_strHTML = m_tf.ReadAll
'Write m_strHTML
Set m_tf = Nothing
Set m_fso = Nothing
SendMail "admin@ny.com", "iamchn@263.net", "HTML Mail!", m_strHTML, 2, 1, Null
'參數(shù)說(shuō)明
'strFrom : 發(fā)件人Email
'strTo : 收件人Email
'strSubject : 信件主題
'strBody : 信件正文
'lngImportance : 信件重要性
' : 0 - 低重要性
' : 0 - 中等重要性(默認(rèn))
' : 0 - 高重要性
'lngAType : 信件格式
' : 為1時(shí)將郵件正文作為HTML(此時(shí)可以發(fā)送HTML郵件)
'strAttach : 附件的路徑
Sub SendMail(strFrom, strTo, strSubject, strBody, lngImportance, lngAType, strAttach)
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
With objMail
.From = strFrom
.To = strTo
.Subject = strSubject
.Body = strBody
.Importance = lngImportance
If lngAType = 1 Then
.BodyFormat = 0
.MailFormat = 0
End If
If IsEmpty(strAttach) = False And IsNull(strAttach) = False Then
.AttachFile strAttach
End If
.Send
End With
Set objMail = Nothing
End Sub
%>
處理驅(qū)動(dòng)器和文件夾
使用 FileSystemObject (FSO) 對(duì)象模式,可以有計(jì)劃地處理驅(qū)動(dòng)器和文件夾,就像在 Windows 資源管理器中交互式地處理它們一樣?梢詮(fù)制和移動(dòng)文件夾,獲取有關(guān)驅(qū)動(dòng)器和文件夾的信息,等等。
獲取有關(guān)驅(qū)動(dòng)器的信息
可以用 Drive 對(duì)象來(lái)獲得有關(guān)各種驅(qū)動(dòng)器的信息,這些驅(qū)動(dòng)器是實(shí)物地或通過(guò)網(wǎng)絡(luò)連接到系統(tǒng)上的。它的屬性可以用來(lái)獲得下面的信息內(nèi)容:
驅(qū)動(dòng)器的總?cè)萘,以字?jié)為單位(TotalSize 屬性)
驅(qū)動(dòng)器的可用空間是多少,以字節(jié)為單位(AvailableSpace 或 FreeSpace 屬性)
哪個(gè)號(hào)被賦給了該驅(qū)動(dòng)器(DriveLetter 屬性)
驅(qū)動(dòng)器的類(lèi)型是什么,如可移動(dòng)的、固定的、網(wǎng)絡(luò)的、CD-ROM 或 RAM 磁盤(pán)(DriveType 屬性)
驅(qū)動(dòng)器的序列號(hào)(SerialNumber 屬性)
驅(qū)動(dòng)器使用的文件系統(tǒng)類(lèi)型,如 FAT、FAT32、NTFS 等等(FileSystem 屬性)
驅(qū)動(dòng)器是否可以使用(IsReady 屬性)
共享和/或卷的名字(ShareName 和 VolumeName 屬性)
驅(qū)動(dòng)器的路徑或根文件夾(Path 和 RootFolder 屬性)
請(qǐng)考察示例代碼,來(lái)領(lǐng)會(huì)如何在 FileSystemObject 中使用這些屬性。
Drive 對(duì)象用法示例
使用 Drive 對(duì)象來(lái)收集有關(guān)驅(qū)動(dòng)器的信息。在下面的代碼中,沒(méi)有對(duì)實(shí)際的 Drive 對(duì)象的引用;相反,使用 GetDrive 方法來(lái)獲得現(xiàn)有 Drive 對(duì)象的引用(在這個(gè)例子中就是 drv)。
下面示例示范了如何在 VBScript 中使用 Drive 對(duì)象:
Sub ShowDriveInfo(drvPath)
Dim fso, drv, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set drv = fso.GetDrive(fso.GetDriveName(drvPath))
s = "Drive " & UCase(drvPath) & " - "
s = s & drv.VolumeName & "<br/>"
s = s & "Total Space: " & FormatNumber(drv.TotalSize / 1024, 0)
s = s & " Kb" & "<br/>"
s = s & "Free Space: " & FormatNumber(drv.FreeSpace / 1024, 0)
s = s & " Kb" & "<br/>"
Response.Write s
End Sub
下面的代碼說(shuō)明在 JScript 中實(shí)現(xiàn)同樣的功能:
function ShowDriveInfo1(drvPath)
{
var fso, drv, s ="";
fso = new ActiveXObject("Scripting.FileSystemObject");
drv = fso.GetDrive(fso.GetDriveName(drvPath));
s += "Drive " + drvPath.toUpperCase()+ " - ";
s += drv.VolumeName + "<br/>";
s += "Total Space: " + drv.TotalSize / 1024;
s += " Kb" + "<br/>";
s += "Free Space: " + drv.FreeSpace / 1024;
s += " Kb" + "<br/>";
Response.Write(s);
}
處理文件夾
在下面的表中,描述了普通的文件夾任務(wù)和執(zhí)行它們的方法。
任務(wù) 方法
創(chuàng)建文件夾。 FileSystemObject.CreateFolder
刪除文件夾。 Folder.Delete 或 FileSystemObject.DeleteFolder
移動(dòng)文件夾。 Folder.Move 或 FileSystemObject.MoveFolder
復(fù)制文件夾。 Folder.Copy 或 FileSystemObject.CopyFolder
檢索文件夾的名字。 Folder.Name
如果文件夾在驅(qū)動(dòng)器上存在,則找出它。 FileSystemObject.FolderExists
獲得現(xiàn)有 Folder 對(duì)象的實(shí)例。 FileSystemObject.GetFolder
找出文件夾的父文件夾名。 FileSystemObject.GetParentFolderName
找出系統(tǒng)文件夾的路徑。 FileSystemObject.GetSpecialFolder
請(qǐng)考察示例代碼,來(lái)看看在 FileSystemObject 中使用了多少種這些的方法和屬性。
下面的示例示范了如何在 VBScript 中使用 Folder 和 FileSystemObject 對(duì)象,來(lái)操作文件夾和獲得有關(guān)它們的信息:
Sub ShowFolderInfo()
Dim fso, fldr, s
' 獲得 FileSystemObject 的實(shí)例。
Set fso = CreateObject("Scripting.FileSystemObject")
' 獲得 Drive 對(duì)象。
Set fldr = fso.GetFolder("c:")
' 打印父文件夾名字。
Response.Write "Parent folder name is: " & fldr & "<br/>"
' 打印驅(qū)動(dòng)器名字。
Response.Write "Contained on drive " & fldr.Drive & "<br/>"
' 打印根文件名。
If fldr.IsRootFolder = True Then
Response.Write "This is the root folder." & ""<br/>"<br/>"
Else
Response.Write "This folder isn't a root folder." & "<br/><br/>"
End If
' 用 FileSystemObject 對(duì)象創(chuàng)建新的文件夾。
fso.CreateFolder ("C:\Bogus")
Response.Write "Created folder C:\Bogus" & "<br/>"
' 打印文件夾的基本名字。
Response.Write "Basename = " & fso.GetBaseName("c:\bogus") & "<br/>"
' 刪除新創(chuàng)建的文件夾。
fso.DeleteFolder ("C:\Bogus")
Response.Write "Deleted folder C:\Bogus" & "<br/>"
End Sub
下面的示例顯示如何在 JScript 中使用 Folder 和 FileSystemObject 對(duì)象:
function ShowFolderInfo()
{
var fso, fldr, s = "";
// 獲得 FileSystemObject 的實(shí)例。
fso = new ActiveXObject("Scripting.FileSystemObject");
// 獲得 Drive 對(duì)象。
fldr = fso.GetFolder("c:");
// 打印父文件夾名。
Response.Write("Parent folder name is: " + fldr + "<br/>");
// 打印驅(qū)動(dòng)器名字。
Response.Write("Contained on drive " + fldr.Drive + "<br/>");
// 打印根文件名。
if (fldr.IsRootFolder)
Response.Write("This is the root folder.");
else
Response.Write("This folder isn't a root folder.");
Response.Write("<br/><br/>");
// 用 FileSystemObject 對(duì)象創(chuàng)建新的文件夾。
fso.CreateFolder ("C:\\Bogus");
Response.Write("Created folder C:\\Bogus" + "<br/>");
// 打印文件夾的基本名。
Response.Write("Basename = " + fso.GetBaseName("c:\\bogus") + "<br/>");
// 刪除新創(chuàng)建的文件夾。
fso.DeleteFolder ("C:\\Bogus");
Response.Write("Deleted folder C:\\Bogus" + "<br/>");
}
ASP分頁(yè)函數(shù)
Function ExportPageInfo(ByRef rs,curpage,i,LinkFile)
Dim retval, j, pageNumber, BasePage
retval = "第" & curpage & "頁(yè)/總" & rs.pagecount & "頁(yè) "
retval = retval & "本頁(yè)" & i & "條/總" & rs.recordcount & "條 "
If curpage = 1 Then
retval = retval & "首頁(yè) 前頁(yè) "
Else
retval = retval & "<a href='" & LinkFile & "page=1'>首頁(yè)</a> <a href='" & LinkFile & "page=" & cstr(curpage - 1) & "'>前頁(yè)</a> "
End If
If curpage = rs.pagecount Then
retval = retval & "后頁(yè) 末頁(yè)"
Else
retval = retval & "<a href='" & LinkFile & "page=" & cstr(curpage + 1) & "'>后頁(yè)</a> <a href='" & LinkFile & "page=" & cstr(rs.pagecount) & "'>末頁(yè)</a>"
End if
retval = retval & "<br/>"
BasePage = (curpage \ 10) * 10
If BasePage > 0 Then retval = retval & " <a href='" & LinkFile & "page=" & (BasePage - 9) & "'><<</a>"
For j = 1 to 10
pageNumber = BasePage + j
If PageNumber > rs.pagecount Then Exit For
If pageNumber = Cint(curpage) Then
retval = retval & " <font color='#FF0000'>" & pageNumber & "</font>"
Else
retval = retval & " <a href='" & LinkFile & "page=" & pageNumber & "'>" & pageNumber & "</a>"
End If
Next
If rs.pagecount > BasePage Then retval = retval & " <a href='" & LinkFile & "page=" & (BasePage + 11) & "'>>></a>"
ExportPageInfo = retval
End Function
應(yīng)用
<%
adoPageRS.open "SELECT * FROM news ORDER BY addtime DESC", conn, 1, 1
if err.number <> 0 then
response.write "數(shù)據(jù)庫(kù)操作失。"&err.description
else
if adoPageRS.eof and adoPageRS.bof then
response.write "沒(méi)有記錄"
else
%>
<div align="center">
<center>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr class="big">
<td width="60%">新 聞 標(biāo) 題</td>
<td width="25%" align="center">日期</td>
<td width="15%" align="center">操 作</td>
</tr>
<%
adoPageRS.pagesize = 10
adoPageRS.absolutepage = curpage
for i = 0 to 9
%>
<tr>
<td><%= adoPageRS("title") %></td>
<td align="center">
<% = adoPageRS("addtime") %>
</td>
<td align="center"><a href='newsman.asp?action=edit&id=<%= adoPageRS("id")%>'>編輯</a>
<a href='javascript:confirmDel(<%= adoPageRS("id") %>)'>刪除</a></td>
</tr>
<%
adoPageRS.movenext
if adoPageRS.eof then
i = i + 1
exit for
End If
next
%>
<tr align="center">
<td colspan="3">
<% = ExportPageInfo(adoPageRS, curpage, i, "Newsman.asp?") %>
</td>
</tr>
</table>
</center>
</div>
asp常常用到的一些東西
<%=Request.ServerVariables("remote_addr")%>
FOR each item in Request.form
tempvalue=trim(Request(item))
tempvalue=Replace(tempvalue,chr(13)&chr(10),"<br/>")
tempvalue=Replace(tempvalue,"<br/><br/>","<br/>")
if tempvalue="" then tempvalue=0
Execute item&"="""&tempvalue&""""
'response.write item&"="&tempvalue&"<br/>"
next
'response.write request("id")
'response.end
if ="" then
response.write "<script language='javascript'>window.alert('')</script>"
response.write "<script language='javascript'>window.history.go(-1);</script>"
response.end
end if
<!--#include file="" -->
<!--#include virtual="" -->
sql="select max(id) from pack"
set RS=conn.execute(sql)
if isnull(RS(0)) then
id=1
else
id=RS(0)+1
end if
set rs=nothing
sql="insert into pack(id,strpackdm,strusername) values("&id&",'"&strpackdm&"','"&Session("username")&"')"
set RS=conn.execute(sql)
sql="update pack set "&Itemname&"='"&tempvalue&"' where id="&id&""
if Itemname<>"id" then
response.write sql&"<br/>"
set rs=conn.execute(sql)
if err.number<>0 then
'錯(cuò)誤處理
response.write "數(shù)據(jù)庫(kù)操作失。" & err.description
err.clear
end if
Set rs=Nothing
Conn.close
Set conn=Nothing
do while not rs.eof and rowcount>0
rowcount=rowcount-1
rs.MoveNext
do while not rs.eof
rs.MoveNext
loop
for each item in rs2.fields
Execute item.name&"="""&trim(rs2(""&item.name&""))&""""
next
function Mycn(str)
str=lcase(str)
str=replace(str,"","")
response.write str
end function
dim conn
dim connstr
on error resume next
set conn=server.CreateObject("adodb.connection")
Connstr="driver=SQL Server; server="&servername&"; uid="&username&"; pwd="&passWord&"; database="&datebasename&";"
Connstr="DBQ="+server.mappath(mydbpath&mdbname)+";DRIVER={Microsoft Access Driver (*.mdb)};"
'response.write Connstr
'response.end
conn.Open connstr
if err<>0 then
Response.Write "無(wú)法建立到數(shù)據(jù)庫(kù)的連接!"
end if
MD5不可逆加密算法的ASP實(shí)現(xiàn)實(shí)例
此為國(guó)外轉(zhuǎn)載函數(shù),可將任意字符轉(zhuǎn)換為md5 16為字符加密形式,而且為不可逆轉(zhuǎn)換。
<%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32
Private m_lOnBits(30)
Private m_l2Power(30)
Private Function LShift(lvalue, iShiftBits)
If iShiftBits = 0 Then
LShift = lvalue
Exit Function
ElseIf iShiftBits = 31 Then
If lvalue And 1 Then
LShift = &H80000000
Else
LShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
Err.Raise 6
End If
If (lvalue And m_l2Power(31 - iShiftBits)) Then
LShift = ((lvalue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
Else
LShift = ((lvalue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
End If
End Function
Private Function RShift(lvalue, iShiftBits)
If iShiftBits = 0 Then
RShift = lvalue
Exit Function
ElseIf iShiftBits = 31 Then
If lvalue And &H80000000 Then
RShift = 1
Else
RShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
Err.Raise 6
End If
RShift = (lvalue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
If (lvalue And &H80000000) Then
RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
End If
End Function
Private Function RotateLeft(lvalue, iShiftBits)
RotateLeft = LShift(lvalue, iShiftBits) Or RShift(lvalue, (32 - iShiftBits))
End Function
Private Function AddUnsigned(lX, lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult
lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If
AddUnsigned = lResult
End Function
Private Function md5_F(x, y, z)
md5_F = (x And y) Or ((Not x) And z)
End Function
Private Function md5_G(x, y, z)
md5_G = (x And z) Or (y And (Not z))
End Function
Private Function md5_H(x, y, z)
md5_H = (x Xor y Xor z)
End Function
Private Function md5_I(x, y, z)
md5_I = (y Xor (x Or (Not z)))
End Function
Private Sub md5_FF(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_F(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub md5_GG(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_G(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub md5_HH(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_H(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub md5_II(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_I(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Function ConvertToWordArray(sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount
Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 448
lMessageLength = Len(sMessage)
lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray(lNumberOfWords - 1)
lBytePosition = 0
lByteCount = 0
Do Until lByteCount >= lMessageLength
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
lByteCount = lByteCount + 1
Loop
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)
lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
ConvertToWordArray = lWordArray
End Function
Private Function WordToHex(lvalue)
Dim lByte
Dim lCount
For lCount = 0 To 3
lByte = RShift(lvalue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
Next
End Function
Top
MD5不可逆加密算法的ASP實(shí)現(xiàn)實(shí)例
--------------------------------------
Public Function MD5(sMessage)
m_lOnBits(0) = CLng(1)
m_lOnBits(1) = CLng(3)
m_lOnBits(2) = CLng(7)
m_lOnBits(3) = CLng(15)
m_lOnBits(4) = CLng(31)
m_lOnBits(5) = CLng(63)
m_lOnBits(6) = CLng(127)
m_lOnBits(7) = CLng(255)
m_lOnBits(8) = CLng(511)
m_lOnBits(9) = CLng(1023)
m_lOnBits(10) = CLng(2047)
m_lOnBits(11) = CLng(4095)
m_lOnBits(12) = CLng(8191)
m_lOnBits(13) = CLng(16383)
m_lOnBits(14) = CLng(32767)
m_lOnBits(15) = CLng(65535)
m_lOnBits(16) = CLng(131071)
m_lOnBits(17) = CLng(262143)
m_lOnBits(18) = CLng(524287)
m_lOnBits(19) = CLng(1048575)
m_lOnBits(20) = CLng(2097151)
m_lOnBits(21) = CLng(4194303)
m_lOnBits(22) = CLng(8388607)
m_lOnBits(23) = CLng(16777215)
m_lOnBits(24) = CLng(33554431)
m_lOnBits(25) = CLng(67108863)
m_lOnBits(26) = CLng(134217727)
m_lOnBits(27) = CLng(268435455)
m_lOnBits(28) = CLng(536870911)
m_lOnBits(29) = CLng(1073741823)
m_lOnBits(30) = CLng(2147483647)
m_l2Power(0) = CLng(1)
m_l2Power(1) = CLng(2)
m_l2Power(2) = CLng(4)
m_l2Power(3) = CLng(8)
m_l2Power(4) = CLng(16)
m_l2Power(5) = CLng(32)
m_l2Power(6) = CLng(64)
m_l2Power(7) = CLng(128)
m_l2Power(8) = CLng(256)
m_l2Power(9) = CLng(512)
m_l2Power(10) = CLng(1024)
m_l2Power(11) = CLng(2048)
m_l2Power(12) = CLng(4096)
m_l2Power(13) = CLng(8192)
m_l2Power(14) = CLng(16384)
m_l2Power(15) = CLng(32768)
m_l2Power(16) = CLng(65536)
m_l2Power(17) = CLng(131072)
m_l2Power(18) = CLng(262144)
m_l2Power(19) = CLng(524288)
m_l2Power(20) = CLng(1048576)
m_l2Power(21) = CLng(2097152)
m_l2Power(22) = CLng(4194304)
m_l2Power(23) = CLng(8388608)
m_l2Power(24) = CLng(16777216)
m_l2Power(25) = CLng(33554432)
m_l2Power(26) = CLng(67108864)
m_l2Power(27) = CLng(134217728)
m_l2Power(28) = CLng(268435456)
m_l2Power(29) = CLng(536870912)
m_l2Power(30) = CLng(1073741824)
Dim x
Dim k
Dim AA
Dim BB
Dim CC
Dim DD
Dim a
Dim b
Dim c
Dim d
Const S11 = 7
Const S12 = 12
Const S13 = 17
Const S14 = 22
Const S21 = 5
Const S22 = 9
Const S23 = 14
Const S24 = 20
Const S31 = 4
Const S32 = 11
Const S33 = 16
Const S34 = 23
Const S41 = 6
Const S42 = 10
Const S43 = 15
Const S44 = 21
x = ConvertToWordArray(sMessage)
a = &H67452301
b = &HEFCDAB89
c = &H98BADCFE
d = &H10325476
For k = 0 To UBound(x) Step 16
AA = a
BB = b
CC = c
DD = d
md5_FF a, b, c, d, x(k + 0), S11, &HD76AA478
md5_FF d, a, b, c, x(k + 1), S12, &HE8C7B756
md5_FF c, d, a, b, x(k + 2), S13, &H242070DB
md5_FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
md5_FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
md5_FF d, a, b, c, x(k + 5), S12, &H4787C62A
md5_FF c, d, a, b, x(k + 6), S13, &HA8304613
md5_FF b, c, d, a, x(k + 7), S14, &HFD469501
md5_FF a, b, c, d, x(k + 8), S11, &H698098D8
md5_FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
md5_FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
md5_FF b, c, d, a, x(k + 11), S14, &H895CD7BE
md5_FF a, b, c, d, x(k + 12), S11, &H6B901122
md5_FF d, a, b, c, x(k + 13), S12, &HFD987193
md5_FF c, d, a, b, x(k + 14), S13, &HA679438E
md5_FF b, c, d, a, x(k + 15), S14, &H49B40821
md5_GG a, b, c, d, x(k + 1), S21, &HF61E2562
md5_GG d, a, b, c, x(k + 6), S22, &HC040B340
md5_GG c, d, a, b, x(k + 11), S23, &H265E5A51
md5_GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA
md5_GG a, b, c, d, x(k + 5), S21, &HD62F105D
md5_GG d, a, b, c, x(k + 10), S22, &H2441453
md5_GG c, d, a, b, x(k + 15), S23, &HD8A1E681
md5_GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8
md5_GG a, b, c, d, x(k + 9), S21, &H21E1CDE6
md5_GG d, a, b, c, x(k + 14), S22, &HC33707D6
md5_GG c, d, a, b, x(k + 3), S23, &HF4D50D87
md5_GG b, c, d, a, x(k + 8), S24, &H455A14ED
md5_GG a, b, c, d, x(k + 13), S21, &HA9E3E905
md5_GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8
md5_GG c, d, a, b, x(k + 7), S23, &H676F02D9
md5_GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A
md5_HH a, b, c, d, x(k + 5), S31, &HFFFA3942
md5_HH d, a, b, c, x(k + 8), S32, &H8771F681
md5_HH c, d, a, b, x(k + 11), S33, &H6D9D6122
md5_HH b, c, d, a, x(k + 14), S34, &HFDE5380C
md5_HH a, b, c, d, x(k + 1), S31, &HA4BEEA44
md5_HH d, a, b, c, x(k + 4), S32, &H4BDECFA9
md5_HH c, d, a, b, x(k + 7), S33, &HF6BB4B60
md5_HH b, c, d, a, x(k + 10), S34, &HBEBFBC70
md5_HH a, b, c, d, x(k + 13), S31, &H289B7EC6
md5_HH d, a, b, c, x(k + 0), S32, &HEAA127FA
md5_HH c, d, a, b, x(k + 3), S33, &HD4EF3085
md5_HH b, c, d, a, x(k + 6), S34, &H4881D05
md5_HH a, b, c, d, x(k + 9), S31, &HD9D4D039
md5_HH d, a, b, c, x(k + 12), S32, &HE6DB99E5
md5_HH c, d, a, b, x(k + 15), S33, &H1FA27CF8
md5_HH b, c, d, a, x(k + 2), S34, &HC4AC5665
md5_II a, b, c, d, x(k + 0), S41, &HF4292244
md5_II d, a, b, c, x(k + 7), S42, &H432AFF97
md5_II c, d, a, b, x(k + 14), S43, &HAB9423A7
md5_II b, c, d, a, x(k + 5), S44, &HFC93A039
md5_II a, b, c, d, x(k + 12), S41, &H655B59C3
md5_II d, a, b, c, x(k + 3), S42, &H8F0CCC92
md5_II c, d, a, b, x(k + 10), S43, &HFFEFF47D
md5_II b, c, d, a, x(k + 1), S44, &H85845DD1
md5_II a, b, c, d, x(k + 8), S41, &H6FA87E4F
md5_II d, a, b, c, x(k + 15), S42, &HFE2CE6E0
md5_II c, d, a, b, x(k + 6), S43, &HA3014314
md5_II b, c, d, a, x(k + 13), S44, &H4E0811A1
md5_II a, b, c, d, x(k + 4), S41, &HF7537E82
md5_II d, a, b, c, x(k + 11), S42, &HBD3AF235
md5_II c, d, a, b, x(k + 2), S43, &H2AD7D2BB
md5_II b, c, d, a, x(k + 9), S44, &HEB86D391
a = AddUnsigned(a, AA)
b = AddUnsigned(b, BB)
c = AddUnsigned(c, CC)
d = AddUnsigned(d, DD)
Next
MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
' MD5=LCase(WordToHex(b) & WordToHex(c)) 'I crop this to fit 16byte database password :D
End Function
Response.Write "123456的加密結(jié)果為[" & md5 ("123456") & "]"
%>