标签归档: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.miaoqiyuan.cn/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.miaoqiyuan.cn/p/iis-log-tools   =
'=      作者博客:http://www.miaoqiyuan.cn                   =
'=      版权声明:本代码供站长免费使用,传播请保留版权信息   =
'=============================================================
'=   程序简介:在网上找了很多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.miaoqiyuan.cn

生成静态页,文章标题拼音命名重复的解决方法。

刚才发布了一篇文章:ASP/VBScript 汉字转拼音程序,只支持GBK(http://www.miaoqiyuan.cn/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

实际这个程序很多地方都能用到,以前我也用过,今天在百度上找,竟然没找到。现在发上来,供以后备份。
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>

双击盘符目录打开该目录,双击文件可打开文件,点击下面的文本框,可以获取目录与文件名
程序比较简单,就不加注释了