標簽歸檔:VBscript

vbs寫的IIS日志分析工具

vbs寫的IIS日志分析工具

IIS日志分析系統

為什么要開發vbs寫的IIS日志分析工具?

在網上找了很多IIS日志分析工具,功能實在太有限,有的僅能分析百度、谷歌等搜索引擎爬蟲的來訪次數,遠遠達不到我們的用戶的需求。作為一個小站長,有的時候也要分析一下自己站點的廣告點擊情況,靜態頁面的還好說,下載類的業務就不好統計了。耗時一晚上寫出來本工具分享給大家,同時申請落伍,請大家幫頂。申請地址:http://www.im286.com/thread-5021543-1-1.html 。

IIS日志分析工具的使用方法

本工具對于初次接收vbs腳本的用戶來說,可能有點麻煩。下面我們就一步一步來說說該工具的使用方法。
1、如果 vbscript 默認引擎非cscript,需要修改稱cscript。修改方法很簡單,直接在運行中輸入:cscript //Nologo //H:Cscript 即可切換

2、下載IIS日志分析工具 壓縮包 http://www.shiekolong1185.icu/products/iis-log.rar,解壓,打開log.vbs,修改dbpath為您當前解壓的路徑。

3、下載您的log日志文件,刪掉前三行和第四行的#Fields: ,保存文件名為test.txt,保存到解壓目錄。

4、在開始運行中用cmd命令打開命令提示符,直接把 log.vbs拖拽到命令提示符中,回車即可開始分析。

以后會出軟件版本嗎?

會的,不過最近不會,其實現在的代碼,直接拿到vb中,套個界面就比市面上的iis日志工具強大,但是現在實際還沒有成熟,等正式發布時,功能絕對的強大。

IIS日志分析工具是免費的嗎?

是的,本工具供站長免費使用,但是傳播請保留我們的版權信息。也許您的建議將會出現在我們未來的軟件版中。

vbs寫的IIS日志分析工具代碼如下:

'=============================================================
'=             Copyright (c) 2010 貓七(QQ:77068320)          =
'=                  All rights reserverd.                    =
'=============================================================
'=               IIS日志分析系統 v_1.10.0828                 =
'=      使用說明:http://www.shiekolong1185.icu/p/iis-log-tools   =
'=      作者博客:http://www.shiekolong1185.icu                   =
'=      版權聲明:本代碼供站長免費使用,傳播請保留版權信息   =
'=============================================================
'=   程序簡介:在網上找了很多IIS日志分析工具,功能簡單,只能 =
'= 分析爬蟲來訪次數。有時候我們小站長也想分析下廣告點擊情況  =
'= ,這時候市面上的IIS統計工具就無能為力了。耗時一晚上寫出來 =
'= 分享給大家,同時申請落伍,請大家幫頂。                    =
'=   申請地址:http://www.im286.com/thread-5021543-1-1.html  =
'=============================================================
'=  文件:log.vbs                                            =
'=  功能:IIS日志分析,懂程序的朋友可擴展,功能不可限量      =
'=============================================================

dbpath = "D:\log"                  '日志文件所在目錄
tblna = "test.txt"                 '日志文件名,如果修改請同時修改 Schema.ini 中相關節點

function getuag(str)
  if instr(str,"+MSIE+7.0;")>0 then
    getuag = "Internet Explore 7.0"
  elseif instr(str,"+MSIE+8.0;")>0 then
    getuag = "Internet Explore 8.0"
  elseif instr(str,"+MSIE+6.0;")>0 then
    getuag = "Internet Explore 6.0"
  elseif instr(str,"MSIE")>0 then
    getuag = "Internet Explore(Other)"
  elseif instr(str,"curl")>0 then
    getuag = "CUrl"
  else
    getuag = str
  end if
end function

wscript.echo string(60,"=")
wscript.echo "         IIS日志分析工具 By 苗啟源(MiaoQiyuan.cn)"
wscript.echo string(60,"=")

set conn = createobject("ADODB.Connection")
conn.open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath & ";Extended Properties=""text;HDR=YES;FMT=Delimited;"""

set rs = createobject("ADODB.Recordset")

'統計 鏈接訪問次數
statime = timer()
rs.open "select [cs-uri-stem],count([c-ip]) from [" & tblna & "] group by [cs-uri-stem]",conn,1,1
ga = rs.getrows()
rs.close
wscript.echo " = 訪問次數 = | = 獨立訪客 = | = 訪問路徑 = "
wscript.echo string(60,"-")
for i = 0 to ubound(ga,2)
  rsid = rsid + 1
  tme = ga(1,i)
  uri = ga(0,i)
  
  '不支持 COUNT DISTINCT 郁悶,使用笨拙的方法
  rs.open "select DISTINCT [c-ip] from [" & tblna & "] where [cs-uri-stem]='" & uri & "'",conn,1,1
  aip = rs.recordcount
  rs.close
  
  wscript.echo string(10 - len(tme)," ") & tme & "    | " & string(8 - len(aip)," ") & aip & "     | " & uri
next
wscript.echo string(60,"-")
wscript.echo "   統計:" & rsid & "條記錄  查詢用時:" & formatnumber((timer() - statime) * 1000,3)  & "毫秒"
wscript.echo string(60,"-") & vbCrlf


'統計 訪問詳情
for i = 0 to ubound(ga,2)
  rsid = 0
  uri = ga(0,i)
  wscript.echo string(60,"=")
  wscript.echo "         訪問詳情:" & uri
  wscript.echo string(60,"=")
  statime = timer()
  wscript.echo " = 編號 = | = IP地址 = | = 瀏覽器類型 = "
  rs.open "select DISTINCT [c-ip],[cs(User-Agent)] from [" & tblna & "] where [cs-uri-stem]='" & uri & "'",conn,1,1
  do while not rs.eof
    rsid = rsid + 1
    'IP 自動變成了數字,還沒有找到解決方法
    cip = rs(0)
    uag = getuag(rs(1))
    wscript.echo string(8 - len(rsid)," ") & rsid & "  | " & string(8 - len(cip)," ") & cip & "  | " & uag
    rs.movenext
  loop
  rs.close
  wscript.echo string(60,"-")
  wscript.echo "   統計:" & rsid & "條記錄  查詢用時:" & formatnumber((timer() - statime) * 1000,3)  & "毫秒"
  wscript.echo string(60,"-") & vbCrlf
next

淺談數據轉換(導入,導出)的快速解決方法

因為工作需要,經常需要操作數據轉換的工作。比如:從dz導入到pw,或從新云導入到5ucms,把數據從這個表導入到那個表。操作的多了,認為自己對數據庫轉化還是有一定的研究的,今天寫出了,希望能對做同樣工作的朋友一些幫助或者啟發。

一般我完成數據庫轉換的腳本選擇vbscript。原因嗎,簡單當然是一個很重要的因素,更重要的常用的數據庫(如:MySQL)都有ADO的驅動。

數據庫轉化第一步,先要確定目的數據庫的類型和當前數據庫的類型。如果access數據庫轉換成mysql數據庫。則需要先去下載MySQL ADO的驅動。

第二步,連接好數據庫了,現在要分析數據庫對應的字段之間的關系。如果能把需要操作的數據表的字段導出來應該能快很多。既然選擇了vbscript腳本,我們就讓他來幫忙。

'Auth:貓七(Miaoqiyuan.cn)
'outTableCol(表名)
'Desc:返回某表的所有字段
function outTableCol(tbl)
	tablesCol=""
	set rs=createobject("ADODB.Recordset")
	rs.open "select top 1 * from "&tbl,conn,1,1
	for i=0 to rs.fields.count-1
		tablesCol=tablesCol & rs.fields(i).name & ","
	next
	outTableCol=tablesCol
	rs.close
	set rs=nothing
end function

直接使用Wscript.echo outTableCol(表名),哈哈,表明全輸出來了(最好將vbscript的腳本宿主改成cscript)。

第三步,字段的對應關系分析好了,自然要進入實質性的過程了-插入數據。
insert into 語句?No,我們用ADODB.Recordset。使用MySQL數據庫的使用ADODB也可以使用哦,這也是我使用vbscript的另一個原因,vbscript對ado的兼容性不用我說了吧。。。確定了用ADODB.Recordset,寫這種Rs(..)=Rs(..)的方式也是挺麻煩的,現在我們再次請vbscript出山。

'Auth:貓七(Miaoqiyuan.cn)
'CreateRsStr(字段名,用','分隔,兩個字段間的轉換用=>)
'例如:
'CreateRsStr "d_id,d_dme"  #Rs1("d_id")=Rs2("d_id")
'CreateRsStr "d_id=>c_id"  #Rs1("c_id")=Rs2("d_id")
'生成Rs1到Rs2的復制字符串

function CreateRsStr(str)
	strDb=split(str,",")
	StrOut=""
	for each Col in strDb
		if Trim(Col) <>"" then
			if instr(Col,"=>")>0 then
				ColDb=Split(Col,"=>")
				if Trim(ColDb(0)) <> "" and Trim(ColDb(1)) <> "" then
					StrOut=StrOut & "Rs1(""" & ColDb(1) & """)=Rs2(""" & ColDb(0) & """)" & VbCrlf
				end if
			else
				StrOut=StrOut & "Rs1(""" & Col & """)=Rs2(""" & Col & """)" & VbCrlf
			end if
		end if
	next
	CreateRsStr=StrOut
end function

Wscript.echo CreateRsStr(“d_id,d_regstt,d_cpr,d_cprnme,d_urlpri,d_dnspri,d_prd”)一下,看看出來了什么?哈哈,是不是出現了

		'Rs1("d_id")=Rs2("d_id")
		Rs1("d_regstt")=Rs2("d_regstt")
		Rs1("d_cpr")=Rs2("d_cpr")
		Rs1("d_cprnme")=Rs2("d_cprnme")
		Rs1("d_urlpri")=Rs2("d_urlpri")
		Rs1("d_dnspri")=Rs2("d_dnspri")
		Rs1("d_prd")=Rs2("d_prd")

我們直接把他復制到程序中就可以了。上邊的是相同字段名的情況,如果字段名不相同,CreateRsStr也可以處理,Wscript.echo CreateRsStr(“d_id=>a_id,d_regstt=>a_regstt”)。

然后update更新就可以了,導數據簡單吧,如果您有更好的方法,歡迎和我聯系,我的博客是http://www.shiekolong1185.icu

生成靜態頁,文章標題拼音命名重復的解決方法。

剛才發布了一篇文章:ASP/VBScript 漢字轉拼音程序,只支持GBK(http://www.shiekolong1185.icu/p/vbscript-gbk-pinyin)。你可能已經猜出來了,為了SEO優化而轉換為拼音的路徑,用這個函數可以很方便的解決了。但是中國文字博大精深,相同讀音的字太多了,那么上邊說的方法生成的路徑可能就要沖突了,怎么辦呢?在此,我給大家提供一個解決方法。因為是windows平臺,使用vbscript腳本來實現。
實際很簡單。先用like查詢是否有類似的路徑,并記錄結果數tms。如果tms=0怎用拼音,如果結果數大于1,則用拼音&結果數的方法。很簡單吧,給出的代碼如下:

'cscript [thisScriptName.vbs]

set conn=createobject("ADODB.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source=D:\miaoqiyuan\Products\labs\故事\dat\db.mdb"

'table c
'n 故事名稱
'd 標題讀音
'g 故事
'c 出處
'p 標題首寫字母
'u 故事路徑
set rs=createobject("ADODB.recordset")
rs.open "select * from c",conn,3,2
do while not rs.eof
	staTme=timer
	tms=conn.execute("select count(u) from c where u like '"&rs("p")&"%'")(0)
	wscript.echo "正在整理"&rs("n")&"中..."
	if tms=0 then
		rs("u")=rs("p")
	else
		rs("u")=rs("p")&tms
	end if
	rs.update
	wscript.echo "整理"&rs("n")&"完畢,用時"&(Timer()-staTme)*1000&"毫秒。"
	rs.movenext
loop

ASP/VBScript 漢字轉拼音程序,只支持GBK

實際這個程序很多地方都能用到,以前我也用過,今天在百度上找,竟然沒找到?,F在發上來,供以后備份。
ASP/VBScript 漢字轉拼音程序,只支持GBK,至于原理嗎,很簡單,不要被Scripting.Dictionary嚇倒了,他只是一個字典。至于拼音對應的數字,哈哈,這個要去分析下gbk的編碼了。這個也是為什么只支持gbk的原因。如果要實現utf-8轉換拼音的方法,直接用一個函數轉換一下就可。在次先不貼出,在網上一搜就能找到。

Set d = createObject("Scripting.Dictionary")
d.add "a",-20319
d.add "ai",-20317
d.add "an",-20304
d.add "ang",-20295
d.add "ao",-20292
d.add "ba",-20283
d.add "bai",-20265
d.add "ban",-20257
d.add "bang",-20242
d.add "bao",-20230
d.add "bei",-20051
d.add "ben",-20036
d.add "beng",-20032
d.add "bi",-20026
d.add "bian",-20002
d.add "biao",-19990
d.add "bie",-19986
d.add "bin",-19982
d.add "bing",-19976
d.add "bo",-19805
d.add "bu",-19784
d.add "ca",-19775
d.add "cai",-19774
d.add "can",-19763
d.add "cang",-19756
d.add "cao",-19751
d.add "ce",-19746
d.add "ceng",-19741
d.add "cha",-19739
d.add "chai",-19728
d.add "chan",-19725
d.add "chang",-19715
d.add "chao",-19540
d.add "che",-19531
d.add "chen",-19525
d.add "cheng",-19515
d.add "chi",-19500
d.add "chong",-19484
d.add "chou",-19479
d.add "chu",-19467
d.add "chuai",-19289
d.add "chuan",-19288
d.add "chuang",-19281
d.add "chui",-19275
d.add "chun",-19270
d.add "chuo",-19263
d.add "ci",-19261
d.add "cong",-19249
d.add "cou",-19243
d.add "cu",-19242
d.add "cuan",-19238
d.add "cui",-19235
d.add "cun",-19227
d.add "cuo",-19224
d.add "da",-19218
d.add "dai",-19212
d.add "dan",-19038
d.add "dang",-19023
d.add "dao",-19018
d.add "de",-19006
d.add "deng",-19003
d.add "di",-18996
d.add "dian",-18977
d.add "diao",-18961
d.add "die",-18952
d.add "ding",-18783
d.add "diu",-18774
d.add "dong",-18773
d.add "dou",-18763
d.add "du",-18756
d.add "duan",-18741
d.add "dui",-18735
d.add "dun",-18731
d.add "duo",-18722
d.add "e",-18710
d.add "en",-18697
d.add "er",-18696
d.add "fa",-18526
d.add "fan",-18518
d.add "fang",-18501
d.add "fei",-18490
d.add "fen",-18478
d.add "feng",-18463
d.add "fo",-18448
d.add "fou",-18447
d.add "fu",-18446
d.add "ga",-18239
d.add "gai",-18237
d.add "gan",-18231
d.add "gang",-18220
d.add "gao",-18211
d.add "ge",-18201
d.add "gei",-18184
d.add "gen",-18183
d.add "geng",-18181
d.add "gong",-18012
d.add "gou",-17997
d.add "gu",-17988
d.add "gua",-17970
d.add "guai",-17964
d.add "guan",-17961
d.add "guang",-17950
d.add "gui",-17947
d.add "gun",-17931
d.add "guo",-17928
d.add "ha",-17922
d.add "hai",-17759
d.add "han",-17752
d.add "hang",-17733
d.add "hao",-17730
d.add "he",-17721
d.add "hei",-17703
d.add "hen",-17701
d.add "heng",-17697
d.add "hong",-17692
d.add "hou",-17683
d.add "hu",-17676
d.add "hua",-17496
d.add "huai",-17487
d.add "huan",-17482
d.add "huang",-17468
d.add "hui",-17454
d.add "hun",-17433
d.add "huo",-17427
d.add "ji",-17417
d.add "jia",-17202
d.add "jian",-17185
d.add "jiang",-16983
d.add "jiao",-16970
d.add "jie",-16942
d.add "jin",-16915
d.add "jing",-16733
d.add "jiong",-16708
d.add "jiu",-16706
d.add "ju",-16689
d.add "juan",-16664
d.add "jue",-16657
d.add "jun",-16647
d.add "ka",-16474
d.add "kai",-16470
d.add "kan",-16465
d.add "kang",-16459
d.add "kao",-16452
d.add "ke",-16448
d.add "ken",-16433
d.add "keng",-16429
d.add "kong",-16427
d.add "kou",-16423
d.add "ku",-16419
d.add "kua",-16412
d.add "kuai",-16407
d.add "kuan",-16403
d.add "kuang",-16401
d.add "kui",-16393
d.add "kun",-16220
d.add "kuo",-16216
d.add "la",-16212
d.add "lai",-16205
d.add "lan",-16202
d.add "lang",-16187
d.add "lao",-16180
d.add "le",-16171
d.add "lei",-16169
d.add "leng",-16158
d.add "li",-16155
d.add "lia",-15959
d.add "lian",-15958
d.add "liang",-15944
d.add "liao",-15933
d.add "lie",-15920
d.add "lin",-15915
d.add "ling",-15903
d.add "liu",-15889
d.add "long",-15878
d.add "lou",-15707
d.add "lu",-15701
d.add "lv",-15681
d.add "luan",-15667
d.add "lue",-15661
d.add "lun",-15659
d.add "luo",-15652
d.add "ma",-15640
d.add "mai",-15631
d.add "man",-15625
d.add "mang",-15454
d.add "mao",-15448
d.add "me",-15436
d.add "mei",-15435
d.add "men",-15419
d.add "meng",-15416
d.add "mi",-15408
d.add "mian",-15394
d.add "miao",-15385
d.add "mie",-15377
d.add "min",-15375
d.add "ming",-15369
d.add "miu",-15363
d.add "mo",-15362
d.add "mou",-15183
d.add "mu",-15180
d.add "na",-15165
d.add "nai",-15158
d.add "nan",-15153
d.add "nang",-15150
d.add "nao",-15149
d.add "ne",-15144
d.add "nei",-15143
d.add "nen",-15141
d.add "neng",-15140
d.add "ni",-15139
d.add "nian",-15128
d.add "niang",-15121
d.add "niao",-15119
d.add "nie",-15117
d.add "nin",-15110
d.add "ning",-15109
d.add "niu",-14941
d.add "nong",-14937
d.add "nu",-14933
d.add "nv",-14930
d.add "nuan",-14929
d.add "nue",-14928
d.add "nuo",-14926
d.add "o",-14922
d.add "ou",-14921
d.add "pa",-14914
d.add "pai",-14908
d.add "pan",-14902
d.add "pang",-14894
d.add "pao",-14889
d.add "pei",-14882
d.add "pen",-14873
d.add "peng",-14871
d.add "pi",-14857
d.add "pian",-14678
d.add "piao",-14674
d.add "pie",-14670
d.add "pin",-14668
d.add "ping",-14663
d.add "po",-14654
d.add "pu",-14645
d.add "qi",-14630
d.add "qia",-14594
d.add "qian",-14429
d.add "qiang",-14407
d.add "qiao",-14399
d.add "qie",-14384
d.add "qin",-14379
d.add "qing",-14368
d.add "qiong",-14355
d.add "qiu",-14353
d.add "qu",-14345
d.add "quan",-14170
d.add "que",-14159
d.add "qun",-14151
d.add "ran",-14149
d.add "rang",-14145
d.add "rao",-14140
d.add "re",-14137
d.add "ren",-14135
d.add "reng",-14125
d.add "ri",-14123
d.add "rong",-14122
d.add "rou",-14112
d.add "ru",-14109
d.add "ruan",-14099
d.add "rui",-14097
d.add "run",-14094
d.add "ruo",-14092
d.add "sa",-14090
d.add "sai",-14087
d.add "san",-14083
d.add "sang",-13917
d.add "sao",-13914
d.add "se",-13910
d.add "sen",-13907
d.add "seng",-13906
d.add "sha",-13905
d.add "shai",-13896
d.add "shan",-13894
d.add "shang",-13878
d.add "shao",-13870
d.add "she",-13859
d.add "shen",-13847
d.add "sheng",-13831
d.add "shi",-13658
d.add "shou",-13611
d.add "shu",-13601
d.add "shua",-13406
d.add "shuai",-13404
d.add "shuan",-13400
d.add "shuang",-13398
d.add "shui",-13395
d.add "shun",-13391
d.add "shuo",-13387
d.add "si",-13383
d.add "song",-13367
d.add "sou",-13359
d.add "su",-13356
d.add "suan",-13343
d.add "sui",-13340
d.add "sun",-13329
d.add "suo",-13326
d.add "ta",-13318
d.add "tai",-13147
d.add "tan",-13138
d.add "tang",-13120
d.add "tao",-13107
d.add "te",-13096
d.add "teng",-13095
d.add "ti",-13091
d.add "tian",-13076
d.add "tiao",-13068
d.add "tie",-13063
d.add "ting",-13060
d.add "tong",-12888
d.add "tou",-12875
d.add "tu",-12871
d.add "tuan",-12860
d.add "tui",-12858
d.add "tun",-12852
d.add "tuo",-12849
d.add "wa",-12838
d.add "wai",-12831
d.add "wan",-12829
d.add "wang",-12812
d.add "wei",-12802
d.add "wen",-12607
d.add "weng",-12597
d.add "wo",-12594
d.add "wu",-12585
d.add "xi",-12556
d.add "xia",-12359
d.add "xian",-12346
d.add "xiang",-12320
d.add "xiao",-12300
d.add "xie",-12120
d.add "xin",-12099
d.add "xing",-12089
d.add "xiong",-12074
d.add "xiu",-12067
d.add "xu",-12058
d.add "xuan",-12039
d.add "xue",-11867
d.add "xun",-11861
d.add "ya",-11847
d.add "yan",-11831
d.add "yang",-11798
d.add "yao",-11781
d.add "ye",-11604
d.add "yi",-11589
d.add "yin",-11536
d.add "ying",-11358
d.add "yo",-11340
d.add "yong",-11339
d.add "you",-11324
d.add "yu",-11303
d.add "yuan",-11097
d.add "yue",-11077
d.add "yun",-11067
d.add "za",-11055
d.add "zai",-11052
d.add "zan",-11045
d.add "zang",-11041
d.add "zao",-11038
d.add "ze",-11024
d.add "zei",-11020
d.add "zen",-11019
d.add "zeng",-11018
d.add "zha",-11014
d.add "zhai",-10838
d.add "zhan",-10832
d.add "zhang",-10815
d.add "zhao",-10800
d.add "zhe",-10790
d.add "zhen",-10780
d.add "zheng",-10764
d.add "zhi",-10587
d.add "zhong",-10544
d.add "zhou",-10533
d.add "zhu",-10519
d.add "zhua",-10331
d.add "zhuai",-10329
d.add "zhuan",-10328
d.add "zhuang",-10322
d.add "zhui",-10315
d.add "zhun",-10309
d.add "zhuo",-10307
d.add "zi",-10296
d.add "zong",-10281
d.add "zou",-10274
d.add "zu",-10270
d.add "zuan",-10262
d.add "zui",-10260
d.add "zun",-10256
d.add "zuo",-10254

function g(num)
	if num>0 and num<160 then
		g=chr(num)
	else
		if num< -20319 or num>-10247 then
			g=""
		else
			a=d.Items
			b=d.keys
			for i=d.count-1 to 0 step -1
				if a(i)< =num then exit for
			next
			g=b(i)
		end if
	end if
end function

function c(str)
	c=""
	for i=1 to len(str)
		c=c&g(asc(mid(str,i,1)))
	next
end function

淺談ASP的Response.write輸出的效率

本文原文地址為:http://miaoqiyuan.cn/p/asp-response-write-xiaolv/,轉載請注明出處。

在網上看到一篇Response.write 的效率的文章,很久了,地址已經找不到了,大約說的是Response.write每行輸出很慢,如果改成字符串會好一些。今天正好是星期天。有空來試驗一下,看看到底對不對。

測試平臺:Windows2003 SP2補丁 IIS6.0
機器配置:Intel E430 CPU(賽揚)
測試內容:
模擬一個網頁輸出的類,使用其Header方法,通過用函數連接的方式(Header2)連接字符串用Response.write輸出,直接連接的方式(Header1)連接用Response.write輸出,Response.write直接輸出的方法,各執行500000次,對比運行結果。
測試代碼:
見附件一
試驗難題:
如果各執行500000,恐怕執行很慢,如果在瀏覽器中打開,恐怕將會直接導致瀏覽器崩潰、IIS恐怕也會崩潰。
解決方法:
1.將執行次數改為10000次。
2.用VBS腳本模擬瀏覽器請求,將結果保存到一個文本文件。代碼見附件二
3.用{VBS腳本模擬瀏覽器請求的腳本的文件名}.vbs>1.txt直接將結果輸出到1.txt
試驗結果:
得到一個大約11.3MB的文本文件,
Header1(輸出直接連接字符串):437.5
Header2(輸出函數連接字符串):703.125
Header3(直接輸出):1406.25
單位:毫秒
試驗結論:
直接輸出連接字符串的方式速度最快,執行1萬次,僅為0.437秒,用函數連接的方式為0.703秒,直接用Response.write輸出的方式最慢,需要1.40秒左右,大約是直接連接輸出方式的3倍,函數連接后輸出的2倍。直接用字符串鏈接的方式效率最高。如果連接的字符串需要經常變動,用函數連接的方式也是一個不錯的選擇。
如果注重ASP輸出效率,而且內容格式不經常變動,建議直接連接。
如果注重ASP輸出效率并且內容格式經常變動,建議用函數連接。
以前認為直接用Response.write輸出的效率最高,現在看來是絕對錯誤的。

附件一:ASP測試文件

'XHTML Class By MiaoQiyuan(flycat,mqycn)
class mqycn_xhtml
	dim mqycn_Title,mqycn_Keyword,mqycn_Style,mqycn_Script,mqycn_Description,mqycn_DiyString,mqycn_html
	public Sub Class_Initialize
		mqycn_Title=""
		mqycn_Keyword=""
		mqycn_Style=""
		mqycn_Script=""
		mqycn_Description=""
		mqycn_DiyString="<xxxxxxxx>11111111</xxxxxxxx>"
	end Sub
 
	Public Function Header1()
		html_tmp="< !DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"&vbCrlf
		html_tmp=html_tmp&"<html xmlns=""http://www.w3.org/1999/xhtml"">"&vbCrlf
		html_tmp=html_tmp&"<head profile=""http://www.w3.org/2000/08/w3c-synd/#"">"&vbCrlf
		html_tmp=html_tmp&"<meta http-equiv=""Content-Type"" content=""text/html; charset=GB2312"" />"&vbCrlf
		html_tmp=html_tmp&"<title></title>"&vbCrlf
		html_tmp=html_tmp&"<meta name=""generator"" content=""FlyCat Images 1.0"" />"&vbCrlf
		html_tmp=html_tmp&"</head></html>"
		Header1=html_tmp&mqycn_DiyString
	End Function
 
	Public Function Header2()
		html_tmp=mqycn_line("<html xmlns=""http://www.w3.org/1999/xhtml"">","< !DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">")
		html_tmp=mqycn_line("<head profile=""http://www.w3.org/2000/08/w3c-synd/#"">",html_tmp)
		html_tmp=mqycn_line("<meta http-equiv=""Content-Type"" content=""text/html; charset=GB2312"" />",html_tmp)
		html_tmp=mqycn_line("<title></title>",html_tmp)
		html_tmp=mqycn_line("<meta name=""generator"" content=""FlyCat Images 1.0"" />",html_tmp)
		html_tmp=mqycn_line("</head></html>",html_tmp)
		Header2=mqycn_line(mqycn_DiyString,html_tmp)
	End Function
 
	Public Sub Header3()
		response.write "< !DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">"&vbCrlf
		response.write "<html xmlns=""http://www.w3.org/1999/xhtml"">"&vbCrlf
		response.write "<head profile=""http://www.w3.org/2000/08/w3c-synd/#"">"&vbCrlf
		response.write "<meta http-equiv=""Content-Type"" content=""text/html; charset=GB2312"" />"&vbCrlf
		response.write "<title></title>"&vbCrlf
		response.write "<meta name=""generator"" content=""FlyCat Images 1.0"" />"&vbCrlf
		response.write mqycn_DiyString&vbCrlf
		response.write "</head></html>"&vbCrlf
	End Sub
 
	Private Function mqycn_line(mqycn_t,mqycn_p)
		mqycn_line=mqycn_p&vbCrlf&mqycn_t
	End Function
 
	Public Function Header()
		times=10000
		response.write string(30,"#")
		response.write string(13," ")&times
		response.write string(30,"#")
		ttt=timer()
		for i=0 to times
			response.write header1()
		next
		tet=(timer()-ttt)*1000
		response.write string(30,"#")
		response.write string(13," ")&times
		response.write string(30,"#")
		ttt=timer()
		for i=0 to times
			response.write header2()
		next
		tdt=(timer()-ttt)*1000
		response.write string(30,"#")
		response.write string(13," ")&times
		response.write string(30,"#")
		ttt=timer()
		for i=0 to times
			call header3()
		next
		Header="Header1(輸出直接連接字符串):"&tet&vbCrlf&"Header2(輸出函數連接字符串):"&tdt&vbCrlf&"Header3(直接輸出):"&(timer()-ttt)*1000
	End Function
end class
 
set html=new mqycn_xhtml
response.write html.Header()
%>

附件二:VBS模擬瀏覽器請求的腳本:

function getHTTPPage(url)  
	dim Http  
	set Http=createobject("MSXML2.XMLHTTP")  
	Http.open "GET",url,false  
	Http.send()  
	if Http.readystate<>4 then  
		exit function  
	end if  
	getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")  
	set http=nothing  
	if err.number<>0 then err.Clear  
end function  
 
Function BytesToBstr(body,Cset)  
	dim objstream  
	set objstream = CreateObject("adodb.stream")  
	objstream.Type = 1  
	objstream.Mode =3  
	objstream.Open  
	objstream.Write body  
	objstream.Position = 0  
	objstream.Type = 2  
	objstream.Charset = Cset  
	BytesToBstr = objstream.ReadText  
	objstream.Close  
	set objstream = nothing  
End Function  
 
Sub Echo(t)
	wscript.echo t&"<br />"&vbcrlf
End Sub
 
echo(getHttpPage("http://192.168.0.3/img/bin/admin"))

用VBScript和Javascript編寫列出所有驅動器所有目錄所有文件的資源管理器

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>FileList with VBScript&Javascript</title>
<script type="text/vbscript">
on error resume next
 
Function Mappath(v)
 Mappath=fso.getAbsolutePathName(v)
End Function
 
Function getPath(style,path)
	pathlist="<select style=""float:left;"&style&""" ondblclick=""javascript:FileMan(this.value)"">"
	if path="" or not fso.folderexists(path) then
		pathlist=pathlist+"<option value="""">我的電腦</option>"
		for each xx in fso.drives
			pathlist=pathlist&"<option value="""&xx&""">"&xx&"\</option>"
		next
	else
		set fpo=fso.getfolder(path)
		'pathlist=pathlist&"<option value="""&path&""">當前目錄==>"&path&"</option>"
		if len(path)>3 then
			pathlist=pathlist&"<option value="""&fpo.parentfolder&""">..</option>"
		else
			pathlist=pathlist&"<option value="""">我的電腦</option>"
		end if
		for each xx in fpo.subfolders
			if i=0 then x=" selected" else x=""
			i=1
			pathlist=pathlist&"<option value="""&xx&""" title="""&xx&""""&x&">"&xx&"</option>"
		next
		pathlist=pathlist&"</select><select style=""float:left;"&style&""" ondblclick=""javascript:openFile(this.value);"">"
		for each xx in fpo.files
			if i=0 then x=" selected" else x=""
			j=1
			pathlist=pathlist&"<option value="""&xx&""" title="""&xx&""""&x&">"&xx&"</option>"
		next
	end if
	pathlist=pathlist&"</select>"
	getPath=pathlist
End Function
 
Sub Loading
	FileMan("D:")
	DriversMan()
End Sub
 
function openFile(v)
	window.open v
end function
 
set fso=CreateObject("Scripting.FileSystemObject")
</script>
<script type="text/javascript">
function gettextarea(){
	ores=document.getElementById("res");
}
function getV(_id,ji){
	var sel=document.getElementsByTagName("select")[ji];
	sel.uid=_id;
	sel.onchange=function(){
		for(i=0;i<sel .options.length;i++){
			if(sel.options[i].selected!=""){
				document.getElementById(sel.uid).value=sel.options[i].value;
			}
		}
	}
}
function _ch(id){
	getV(id,1);
}
function _chf(id){
	getV(id,2);
}
function FileMan(Path){
	var oFm=document.getElementById("fileman");
	oFm.innerHTML=getPath("width:90%;\"  size=\"13",Path);
}
function DriversMan(){
	var oDm=document.getElementById("driversman");
	oDm.innerHTML=getPath("width:9%;\"  size=\"26","");
}
</script>
</sel></script></meta></head>
<body style="background:#D4D0C8;text-align:center" onload="Loading">
<div style="width:100%;height:100%">
	<div><span id="driversman"></span><span id="fileman"></span></div>
	<div>
		<input value="請點擊選擇目錄" onclick="javascript:_ch(this.id);" id="__rst" readonly/>
		<input value="請點擊選擇目錄"  onclick="javascript:_ch(this.id);" id="__res"  readonly/>
		<input value="請點擊選擇文件" onclick="javascript:_chf(this.id);" id="__rstf" readonly/>
		<input value="請點擊選擇文件"  onclick="javascript:_chf(this.id);" id="__resf"  readonly/>
		<input value="請點擊選擇目錄" onclick="javascript:_ch(this.id);" id="__rst1" readonly/>
		<input value="請點擊選擇目錄"  onclick="javascript:_ch(this.id);" id="__res1"  readonly/>
		<input value="請點擊選擇文件" onclick="javascript:_chf(this.id);" id="__rstf1" readonly/>
		<input value="請點擊選擇文件"  onclick="javascript:_chf(this.id);" id="__resf1"  readonly/>
		<input value="請點擊選擇目錄" onclick="javascript:_ch(this.id);" id="__rst2" readonly/>
		<input value="請點擊選擇目錄"  onclick="javascript:_ch(this.id);" id="__res2"  readonly/>
		<input value="請點擊選擇文件" onclick="javascript:_chf(this.id);" id="__rstf2" readonly/>
		<input value="請點擊選擇文件"  onclick="javascript:_chf(this.id);" id="__resf2"  readonly/>
	</div>
</div>
</body>
</html>

雙擊盤符目錄打開該目錄,雙擊文件可打開文件,點擊下面的文本框,可以獲取目錄與文件名
程序比較簡單,就不加注釋了