ASP函数集(3)
作者:admin 日期:2006-07-08
23纯ASP代码生成图表函数
<%
function table2(total,table_x,table_y,all_width,all_height,line_no)
'参数含义(传递的数组,横坐标,纵坐标,图表的宽度,图表的高度,折线条数)
'纯ASP代码生成图表函数2——折线图
'作者:龚鸣(Passwordgm) QQ:25968152 MSN:passwordgm@sina.com Email:passwordgm@sina.com
'本人非常愿意和ASP,VML,FLASH的爱好者在HTTP://topclouds.126.com进行交流和探讨
'版本1.0 最后修改日期 2003-8-11
'非常感谢您使用这个函数,请您使用和转载时保留版权信息,这是对作者工作的最好的尊重。
line_color="#69f"
left_width=70
total_no=ubound(total,1)
temp1=0
for i=1 to total_no
for j=1 to line_no
if temp1next
next
temp1=int(temp1)
if temp1>9 then
temp2=mid(cstr(temp1),2,1)
if temp2>4 then
temp3=(int(temp1/(10^(len(cstr(temp1))-1)))+1)*10^(len(cstr(temp1))-1)
else
temp3=(int(temp1/(10^(len(cstr(temp1))-1)))+0.5)*10^(len(cstr(temp1))-1)
end if
else
if temp1>4 then temp3=10 else temp3=5
end if
temp4=temp3
response.write " "
for i=0 to all_height-1 step all_height/5
response.write " "
response.write " "
response.write ""
response.write ""
response.write "
"
temp4=temp4-temp3/5
next
response.write " "
response.write " "
dim line_code
redim line_code(line_no,5)
for i=1 to line_no
line_temp=split(total(0,i),",")
line_code(i,1)=line_temp(0)
line_code(i,2)=line_temp(1)
line_code(i,3)=line_temp(2)
line_code(i,4)=line_temp(3)
line_code(i,5)=line_temp(4)
next
for j=1 to line_no
for i=1 to total_no-1
x1=table_x+left_width+all_width*(i-1)/total_no
y1=table_y+(temp3-total(i,j))*(all_height/temp3)
x2=table_x+left_width+all_width*i/total_no
y2=table_y+(temp3-total(i+1,j))*(all_height/temp3)
response.write ""
select case line_code(j,3)
case 1
case 2
response.write " "
case 3
response.write " "
case 4
response.write " "
case 5
response.write " "
case 6
response.write " "
case 7
response.write " "
case else
end select
response.write " "&CHR(13)
select case line_code(j,4)
case 1
case 2
response.write ""&CHR(13)
case 3
response.write ""&CHR(13)
end select
next
select case line_code(j,4)
case 1
case 2
response.write ""&CHR(13)
case 3
response.write ""&CHR(13)
end select
next
for i=1 to total_no
response.write " "
response.write ""
response.write ""
response.write "
"
next
tb_height=30
response.write " "
for i=1 to line_no
response.write ""
response.write "
"
response.write " "
next
end function
%>
<%
function table3(total,table_x,table_y,all_width,all_height,table_type)
'参数含义(传递的数组,横坐标,纵坐标,图表的宽度,图表的高度,图表的类型)
'纯ASP代码生成图表函数3——饼图
'作者:龚鸣(Passwordgm) QQ:25968152 MSN:passwordgm@sina.com Email:passwordgm@sina.com
'本人非常愿意和ASP,VML,FLASH的爱好者在HTTP://topclouds.126.com进行交流和探讨
'版本1.0 最后修改日期 2003-8-11
'非常感谢您使用这个函数,请您使用和转载时保留版权信息,这是对作者工作的最好的尊重。
tb_height=30
dim tb_color(7,2)
tb_color(1,1)="#d1ffd1"
tb_color(2,1)="#ffbbbb"
tb_color(3,1)="#ffe3bb"
tb_color(4,1)="#cff4f3"
tb_color(5,1)="#d9d9e5"
tb_color(6,1)="#ffc7ab"
tb_color(7,1)="#ecffb7"
tb_color(1,2)="#00ff00"
tb_color(2,2)="#ff0000"
tb_color(3,2)="#ff9900"
tb_color(4,2)="#33cccc"
tb_color(5,2)="#666699"
tb_color(6,2)="#993300"
tb_color(7,2)="#99cc00"
total_no=ubound(total,1)
totalpie=0
for i=1 to total_no
totalpie=totalpie+total(i,1)
next
PreAngle=0
for i=1 to total_no
response.write " "&CHr(13)
PreAngle=PreAngle+total(i,1)/totalpie
next
if table_type="A" then
response.write " "
for i=1 to total_no
response.write ""
response.write "
"
response.write " "
'显示比例数
' response.write ""
' response.write "
"
next
end if
if table_type="B" then
pie=3.14159265358979
TempPie=0
for i=1 to total_no
TempAngle=pie*2*(total(i,1)/(TotalPie*2)+TempPie)
x1=table_x+all_width/2+cos(TempAngle)*all_width*3/8
y1=table_y+all_height/2-sin(TempAngle)*all_height*3/8
x2=table_x+all_width/2+cos(TempAngle)*all_width*3/4
y2=table_y+all_height/2-sin(TempAngle)*all_height*3/4
if x2>table_x+all_width/2 then
x3=x2+20
x4=x3
else
x3=x2-20
x4=x3-100
end if
response.write " "&CHR(13)
response.write " "
response.write " "
response.write ""
response.write "
"
TempPie=TempPie+total(i,1)/TotalPie
next
end if
end function
%>
24使用ASP在IIS创建WEB站点的函数
<%
'=============================================================
'函数介绍:创建WebSite
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)
'用法:CreateWebSite 计算机名(一搬为LocalHost或127.0.0.1),站点IP地址,端口号,主机名,站点根目录,,LOG文件的目录站点说明,网站访问时所使用的帐号,网站访问时所用帐号的口令,是否启动站点
'例:CreateWebSite "LocalHost","127.0.0.123","80","www.test.net","E:\UserData\UserNum001","E:\UserData\UserNum001\LogFiles","wwwtest.net","IUSR_Num001_test.net","abc888",True
'=============================================================
Function CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)
Dim w3svc, WebServer, NewWebServer, NewDir
Dim Bindings, BindingString, NewBindings, SiteNum, SiteObj, bDone
On Error Resume Next
Err.Clear
'检测是否能够加载W3SVC服务(即WEB服务)
Set w3svc = GetObject("IIS://" & Computer & "/w3svc")
If Err.Number <> 0 Then '显示错误提示
response.write "无法打开: "&"IIS://" & Computer & "/w3svc"
response.end
End If
'检测是否有设定相同IP地址、端口及主机名的站点存在
BindingString = IPAddr & ":" & PortNum & ":" & HostName
For Each WebServer in w3svc
If WebServer.Class = "IIsWebServer" Then
Bindings = WebServer.ServerBindings
If BindingString = Bindings(0) Then
response.write "IP地址冲突:" & IPAddr & ",请检测IP地址!."
Exit Function
End If
End If
Next
'确定一个不存在的站点编号做为新建站点编号,系统默认WebSite站点编号为1,因此从2开始
SiteNum=2
bDone = False
While (Not bDone)
Err.Clear
Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&SiteNum) '加载指定站点
If (Err.Number = 0) Then
'response.write " Step_1站点"&SiteNum&"存在"
SiteNum = SiteNum + 1
Else
'response.write " Step_1站点"&SiteNum&"不存在"
Err.Clear
Set NewWebServer = w3svc.Create("IIsWebServer",SiteNum) '创建指定站点
If (Err.Number <> 0) Then
'response.write " Step_2站点"&SiteNum&"创建失败"
SiteNum = SiteNum + 1
Else
'response.write " Step_2站点"&SiteNum&"创建成功"
bDone = True
End If
End If
If (SiteNum > 50) Then '服务器最大创建站点数
response.write "超出服务器最大创建站点数,正在创建的站点的序号为: "&SiteNum&"."
response.end
End If
Wend
'进行站点基本配置
NewBindings = Array(0)
NewBindings(0) = BindingString
NewWebServer.ServerBindings = NewBindings
NewWebServer.ServerComment= WebSiteInfo
NewWebServer.AnonymousUserName= GuestUserName
NewWebServer.AnonymousUserPass= GuestUserPass
NewWebServer.KeyType = "IIsWebServer"
NewWebServer.FrontPageWeb = True
NewWebServer.EnableDefaultDoc = True
NewWebServer.DefaultDoc = "Default.htm, Default.asp, Index.htm, Index.asp"
NewWebServer.LogFileDirectory= LogDirectory
NewWebServer.SetInfo
Set NewDir = NewWebServer.Create("IIsWebVirtualDir", "ROOT")
NewDir.Path = WebSiteDirectory
NewDir.AccessRead = true
NewDir.AppFriendlyName = "应用程序" & WebSiteInfo
NewDir.AppCreate True
NewDir.AccessScript = True
Err.Clear
NewDir.SetInfo
If (Err.Number <> 0) Then
response.write "主目录创建时出错."
response.end
End If
If StartOrStop = True Then
Err.Clear
Set NewWebServer = GetObject("IIS://" & Computer & "/w3svc/" & SiteNum)
NewWebServer.Start
If Err.Number <> 0 Then
response.write "启动站点时出错!"
response.end
Err.Clear
End If
End If
response.write "站点创建成功,站点编号为:"& SiteNum &" ,域名为:"& HostName
End Function
使用ASP启动/停止指定WEB站点
'=============================================================
'函数介绍:使用ASP启动/停止指定WEB站点
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:AdminWebSite(Computer,WebSiteNum,DoWhat)
'用法:AdminWebSite(计算机名称,站点编号,启动/停止)
'例:启动127.0.0.1计算机上站点编号为1的站点
'AdminWebSite "127.0.0.1","1",1
'例:停止127.0.0.1计算机上站点编号为1的站点
'AdminWebSite "127.0.0.1","1",0
'=============================================================
Function AdminWebSite(Computer,WebSiteNum,DoWhat)
On Error Resume Next
Set objServer = GetObject("IIS://" & Computer & "/W3SVC/" & WebSiteNum)
If Err.Number <> 0 Then
Response.Write Now & ". 错误码: " & Hex(Err)& " - " & "无法开启指定站点
"
End If
if Dowhat=1 then
'使用Start启动站点
objServer.Start
If Err.Number <> 0 Then
Response.Write "无法启动指定Web站点
"
else
Response.Write "已经启动指定Web站点
"
End If
elseif DoWhat=0 then
'使用Stop停止站点
objServer.Stop
If Err.Number <> 0 Then
Response.Write "无法停止指定Web站点
"
else
Response.Write "已经停止指定Web站点
"
End If
end if
End Function
使用ASP列出服务器WEB站点信息
'=============================================================
'函数介绍:列出当前服务器WEB站点信息
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:ListWebSite (Computer,Num)
'用法:ListWebSite (计算机名称,显示站点数量)
'例:显示127.0.0.1计算机上1000个站点信息
'ListWebSite "127.0.0.1","1000"
'=============================================================
Function ListWebSite(Computer,Num)
On Error Resume Next
Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&i)
for i=0 to Num
Err.Clear
if Err.Number=0 then
response.write "
ShowWebSite = SiteObj.Get("ServerBindings") '获得站点IP地址:端口:主机头
Info=split(ShowWebSite(0),":")
response.write "站点编号:"&i&"
"
response.write "站点IP地址:"&Info(0)&"
"
response.write "站点端口:"&Info(1)&"
"
response.write "站点主机头:"&Info(2)&"
"
end if
next
set SiteOjb=nothing
End Function
使用ASP删除指定IIS站点
'=============================================================
'函数介绍:删除指定IIS站点
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:DelWebSite (Computer,SiteNum)
'用法:DelWebSite 计算机名,站点编号
'例:DelWebSite "127.0.0.1","2"
'=============================================================
Function DelWebSite(Computer,SiteNum)
Set W3SVC = GetObject("IIS://"&Computer&"/w3svc")
W3SVC.delete "IIsWebServer",SiteNum
response.write "删除成功!"
End Function
通过ASP管理NT帐号
'=============================================================
'函数介绍:通过ASP管理NT帐号
'本函数使用ADSI,需要Administrators组用户权限
'=============================================================
'填加用户
'函数用法:AddUser(Computer,UserName,PassWord,FullName,Info)
'参数:计算机名,帐号名称,帐号密码,帐号全名,帐号说明
'例:AddUser "127.0.0.1","Test","Test","测试管理员帐号","本帐号通过ASP填加"
'修改指定用户基本信息
'函数用法:EditUser(Computer,UserName,OldPassWord,PassWord,FullName,Info)
'参数:计算机名,帐号名称,帐号密码,帐号全名,帐号说明
'例:EditUser "127.0.0.1","Test","Test2","测试管理员帐号修改","本帐号通过ASP修改过"
'删除指定用户
'函数用法:DelUser(Computer,UserName)
'参数:计算机名,用户名'
'例:DelUser "127.0.0.1","Test"
=============================================================
Function AddUser(Computer,UserName,PassWord,FullName,Info)
'执行创建帐号命令
Set ComputerObj = GetObject("WinNT://"&Computer)
Set NewUser = ComputerObj.Create( "User" , UserName )
NewUser.SetInfo
'进行帐号设置
NewUser.SetPassword ( PassWord ) '帐号密码
NewUser.FullName = FullName '帐号全名
NewUser.Description = Info '帐号说明
NewUser.UserFlags = &H10000 '&H20000(使用者下次登入时须变更密码) &H0040(使用者不得变更密码) &H10000(密码永久正确) &H0002(帐户暂时停用)
NewUser.SetInfo
response.write "帐号"&UserName&"创建成功!"
Set ComputerObj=nothing
End Function
Function EditUser(Computer,UserName,OldPassWord,PassWord,FullName,Info)
'读取用户信息
Set ChangeUserObj = GetObject("WinNT://"&Computer&"/"&UserName&",User")
'修改帐号密码
if PassWord<>"" then
ChangeUserObj.SetPassword PassWord
response.write "帐号密码修改成功!
"
end if
'修改帐号全名
if FullName<>"" then
UserFullName = ChangeUserObj.get("FullName")
ChangeUserObj.FullName = FullName
ChangeUserObj.SetInfo
response.write "帐号全名修改成功!
"
end if
'修改帐号说明
if Info<>"" then
UserFullName = ChangeUserObj.get("Description")
ChangeUserObj.Description = Info
ChangeUserObj.SetInfo
response.write "帐号说明修改成功!
"
end if
Set ChangeUserObj=nothing
End Function
Function DelUser(Computer,UserName)
Set DelUserObj = GetObject("WinNT://"&Computer&"/"&UserName)
If Err = &H800401E4 Then
Response.Write "用户"&UserName&"不存在"
Response.End
End If
Set DelObj = GetObject(DelUserObj.Parent)
DelObj.Delete "User", DelUserObj.Name
Set DelUserObj = Nothing
Set DelObj = Nothing
Response.Write "删除成功"
End Function
使用ASP控制指定站点解析脚本语言函数
Function AdminAegis(Computer,SiteNum)
Set IIsWebServiceObj = GetObject("IIS://"&Computer&"/W3SVC/"&SiteNum)
dim Aegis(1)
Aegis(0)=".asp,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE"
'Aegis(1)=".aspx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG"
'解析其它文件请同样使用Aegis(Num)=""这种格式,记得要将dim Aegis(Num)定义
'.htw,C:\WINNT\system32\webhits.dll,3,GET,HEAD,POST
'.ida,C:\WINNT\system32\idq.dll,7,GET,HEAD,POST
'.idq,C:\WINNT\system32\idq.dll,7,GET,HEAD,POST
'.asp,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.cer,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.cdx,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.asa,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.idc,C:\WINNT\system32\inetsrv\httpodbc.dll,5,GET,POST
'.shtm C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST
'.shtml C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST
'.stm C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST
'.asax C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.ascx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.ashx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.asmx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.aspx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.axd,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.vsdisco,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.rem,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.soap,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.config,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.cs,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.csproj,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.vb,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.vbproj,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.webinfo,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.licx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.resx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.resources,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
IIsWebServiceObj.ScriptMaps=Aegis
IIsWebServiceObj.SetInfo
'显示支持脚本语言
response.write "当前站点支持解析列表:
"
For ValueIndex = 0 To UBound(IIsWebServiceObj.ScriptMaps)
response.write IIsWebServiceObj.Get("ScriptMaps")(ValueIndex)
response.write "
"
Next
End Function
使用ASP列出NT用户组及用户
'=============================================================
'函数介绍:列出NT用户组及用户
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:ListGroup(Computer)
'用法:ListGroup(计算机名称)
'例:显示127.0.0.1计算机NT用户组及用户
'ListGroup "127.0.0.1"
'=============================================================
Function ListGroup(Computer)
response.write "
Set ComputerObj = GetObject("WinNT://"&Computer)
ComputerObj.Filter = Array("Group")
For Each Member in ComputerObj
Response.Write "用户组:"&Member.Name&"
"
ListUser Computer,Member.Name
Next
end Function
'列出指定用户组用户
Function ListUser(Computer,Group)
Set UserObj = GetObject("WinNT://"&Computer&"/"&Group)
For Each Member in UserObj.Members
Response.write " 组中用户:"&Member.Name &"
"
Next
End Function
%>
25.将文字转化为它的源代码格式
<%
public function HtmlOut(str)
'将文字转化为它的源代码格式
dim guest
if isnull(str) or str="" then
htmlOut=str
exit function
end if
guest=str
guest=Replace(Guest," "," ")
guest=Replace(Guest," ","`nbsp;")
Guest=server.htmlencode(Guest)
guest=Replace(Guest,"`nbsp;"," ")
guest=Replace(Guest,vbcrlf,"
")
HtmlOut=guest
end function
%>
26.从数据库中提取内容生成下拉菜单
<%
public function OutOption(conn,tabel,style,value)
'从数据库中提取内容生成下拉菜单
'conn 为数据库联接 table为表名 style下接菜单样式
dim re,sql,selected
set re=server.CreateObject("ADODB.RECORDSET")
sql = "SELECT * FROM " & tabel & " ORDER BY value"
re.Open sql,conn
Response.Write ("" & vbCrlf)
set re=nothing
end function
%>
27.时间格式化函数
<%
Public Function FormatDT(dt, style)
'style=0 2000-10-10 下午 12:17:45
'style=1 2000-10-10 23:17:45
'style=2 2000-10-10 23:45
'style=3 00-10-10 23:45
'style=4 10-10 23:45
'style=5 2000-10-10
'style=6 00-10-10
'style=7 10-10
Dim nowdate, y, m, d, h, i, s, t, APM, hAPM
nowdate = dt
y = Year(nowdate)
m = Month(nowdate)
d = Day(nowdate)
h = Hour(nowdate)
i = Minute(nowdate)
s = Second(nowdate)
If h > 12 Then
APM = "下午 "
hAPM = CStr(CInt(h) Mod 12)
Else
APM = "上午 "
hAPM = h
End If
Select Case style
Case 0
t = y & "-" & m & "-" & d & " " & APM & hAPM & ":" & i & ":" & s
Case 1
t = y & "-" & m & "-" & d & " " & h & ":" & i & ":" & s
Case 2
t = y & "-" & m & "-" & d & " " & h & ":" & i
Case 3
t = Right(y, 2) & "-" & m & "-" & d & " " & h & ":" & i
Case 4
t = m & "-" & d & " " & h & ":" & i
Case 5
t = y & "-" & m & "-" & d
Case 6
t = Right(y, 2) & "-" & m & "-" & d
Case 7
t = m & "-" & d
End Select
FormatDT = t
End Function
%>
<%
function table2(total,table_x,table_y,all_width,all_height,line_no)
'参数含义(传递的数组,横坐标,纵坐标,图表的宽度,图表的高度,折线条数)
'纯ASP代码生成图表函数2——折线图
'作者:龚鸣(Passwordgm) QQ:25968152 MSN:passwordgm@sina.com Email:passwordgm@sina.com
'本人非常愿意和ASP,VML,FLASH的爱好者在HTTP://topclouds.126.com进行交流和探讨
'版本1.0 最后修改日期 2003-8-11
'非常感谢您使用这个函数,请您使用和转载时保留版权信息,这是对作者工作的最好的尊重。
line_color="#69f"
left_width=70
total_no=ubound(total,1)
temp1=0
for i=1 to total_no
for j=1 to line_no
if temp1
next
temp1=int(temp1)
if temp1>9 then
temp2=mid(cstr(temp1),2,1)
if temp2>4 then
temp3=(int(temp1/(10^(len(cstr(temp1))-1)))+1)*10^(len(cstr(temp1))-1)
else
temp3=(int(temp1/(10^(len(cstr(temp1))-1)))+0.5)*10^(len(cstr(temp1))-1)
end if
else
if temp1>4 then temp3=10 else temp3=5
end if
temp4=temp3
response.write "
for i=0 to all_height-1 step all_height/5
response.write "
response.write "
response.write ""
response.write "
response.write "
"&temp4&" |
temp4=temp4-temp3/5
next
response.write "
response.write "
dim line_code
redim line_code(line_no,5)
for i=1 to line_no
line_temp=split(total(0,i),",")
line_code(i,1)=line_temp(0)
line_code(i,2)=line_temp(1)
line_code(i,3)=line_temp(2)
line_code(i,4)=line_temp(3)
line_code(i,5)=line_temp(4)
next
for j=1 to line_no
for i=1 to total_no-1
x1=table_x+left_width+all_width*(i-1)/total_no
y1=table_y+(temp3-total(i,j))*(all_height/temp3)
x2=table_x+left_width+all_width*i/total_no
y2=table_y+(temp3-total(i+1,j))*(all_height/temp3)
response.write "
select case line_code(j,3)
case 1
case 2
response.write "
case 3
response.write "
case 4
response.write "
case 5
response.write "
case 6
response.write "
case 7
response.write "
case else
end select
response.write "
select case line_code(j,4)
case 1
case 2
response.write "
case 3
response.write "
end select
next
select case line_code(j,4)
case 1
case 2
response.write "
case 3
response.write "
end select
next
for i=1 to total_no
response.write "
response.write ""
response.write "
response.write "
"&total(i,0)&" |
next
tb_height=30
response.write "
for i=1 to line_no
response.write "
response.write "
"&line_code(i,5)&" |
response.write "
next
end function
%>
<%
function table3(total,table_x,table_y,all_width,all_height,table_type)
'参数含义(传递的数组,横坐标,纵坐标,图表的宽度,图表的高度,图表的类型)
'纯ASP代码生成图表函数3——饼图
'作者:龚鸣(Passwordgm) QQ:25968152 MSN:passwordgm@sina.com Email:passwordgm@sina.com
'本人非常愿意和ASP,VML,FLASH的爱好者在HTTP://topclouds.126.com进行交流和探讨
'版本1.0 最后修改日期 2003-8-11
'非常感谢您使用这个函数,请您使用和转载时保留版权信息,这是对作者工作的最好的尊重。
tb_height=30
dim tb_color(7,2)
tb_color(1,1)="#d1ffd1"
tb_color(2,1)="#ffbbbb"
tb_color(3,1)="#ffe3bb"
tb_color(4,1)="#cff4f3"
tb_color(5,1)="#d9d9e5"
tb_color(6,1)="#ffc7ab"
tb_color(7,1)="#ecffb7"
tb_color(1,2)="#00ff00"
tb_color(2,2)="#ff0000"
tb_color(3,2)="#ff9900"
tb_color(4,2)="#33cccc"
tb_color(5,2)="#666699"
tb_color(6,2)="#993300"
tb_color(7,2)="#99cc00"
total_no=ubound(total,1)
totalpie=0
for i=1 to total_no
totalpie=totalpie+total(i,1)
next
PreAngle=0
for i=1 to total_no
response.write "
PreAngle=PreAngle+total(i,1)/totalpie
next
if table_type="A" then
response.write "
for i=1 to total_no
response.write "
response.write "
"&total(i,0)&" |
response.write "
'显示比例数
' response.write "
' response.write "
"&formatnumber(total(i,1)*100/totalpie,2,-1)&"% |
next
end if
if table_type="B" then
pie=3.14159265358979
TempPie=0
for i=1 to total_no
TempAngle=pie*2*(total(i,1)/(TotalPie*2)+TempPie)
x1=table_x+all_width/2+cos(TempAngle)*all_width*3/8
y1=table_y+all_height/2-sin(TempAngle)*all_height*3/8
x2=table_x+all_width/2+cos(TempAngle)*all_width*3/4
y2=table_y+all_height/2-sin(TempAngle)*all_height*3/4
if x2>table_x+all_width/2 then
x3=x2+20
x4=x3
else
x3=x2-20
x4=x3-100
end if
response.write "
response.write "
response.write "
response.write "
response.write "
"&total(i,0)&" "&formatnumber(total(i,1)*100/totalpie,2,-1)&"% |
TempPie=TempPie+total(i,1)/TotalPie
next
end if
end function
%>
24使用ASP在IIS创建WEB站点的函数
<%
'=============================================================
'函数介绍:创建WebSite
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)
'用法:CreateWebSite 计算机名(一搬为LocalHost或127.0.0.1),站点IP地址,端口号,主机名,站点根目录,,LOG文件的目录站点说明,网站访问时所使用的帐号,网站访问时所用帐号的口令,是否启动站点
'例:CreateWebSite "LocalHost","127.0.0.123","80","www.test.net","E:\UserData\UserNum001","E:\UserData\UserNum001\LogFiles","wwwtest.net","IUSR_Num001_test.net","abc888",True
'=============================================================
Function CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)
Dim w3svc, WebServer, NewWebServer, NewDir
Dim Bindings, BindingString, NewBindings, SiteNum, SiteObj, bDone
On Error Resume Next
Err.Clear
'检测是否能够加载W3SVC服务(即WEB服务)
Set w3svc = GetObject("IIS://" & Computer & "/w3svc")
If Err.Number <> 0 Then '显示错误提示
response.write "无法打开: "&"IIS://" & Computer & "/w3svc"
response.end
End If
'检测是否有设定相同IP地址、端口及主机名的站点存在
BindingString = IPAddr & ":" & PortNum & ":" & HostName
For Each WebServer in w3svc
If WebServer.Class = "IIsWebServer" Then
Bindings = WebServer.ServerBindings
If BindingString = Bindings(0) Then
response.write "IP地址冲突:" & IPAddr & ",请检测IP地址!."
Exit Function
End If
End If
Next
'确定一个不存在的站点编号做为新建站点编号,系统默认WebSite站点编号为1,因此从2开始
SiteNum=2
bDone = False
While (Not bDone)
Err.Clear
Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&SiteNum) '加载指定站点
If (Err.Number = 0) Then
'response.write " Step_1站点"&SiteNum&"存在"
SiteNum = SiteNum + 1
Else
'response.write " Step_1站点"&SiteNum&"不存在"
Err.Clear
Set NewWebServer = w3svc.Create("IIsWebServer",SiteNum) '创建指定站点
If (Err.Number <> 0) Then
'response.write " Step_2站点"&SiteNum&"创建失败"
SiteNum = SiteNum + 1
Else
'response.write " Step_2站点"&SiteNum&"创建成功"
bDone = True
End If
End If
If (SiteNum > 50) Then '服务器最大创建站点数
response.write "超出服务器最大创建站点数,正在创建的站点的序号为: "&SiteNum&"."
response.end
End If
Wend
'进行站点基本配置
NewBindings = Array(0)
NewBindings(0) = BindingString
NewWebServer.ServerBindings = NewBindings
NewWebServer.ServerComment= WebSiteInfo
NewWebServer.AnonymousUserName= GuestUserName
NewWebServer.AnonymousUserPass= GuestUserPass
NewWebServer.KeyType = "IIsWebServer"
NewWebServer.FrontPageWeb = True
NewWebServer.EnableDefaultDoc = True
NewWebServer.DefaultDoc = "Default.htm, Default.asp, Index.htm, Index.asp"
NewWebServer.LogFileDirectory= LogDirectory
NewWebServer.SetInfo
Set NewDir = NewWebServer.Create("IIsWebVirtualDir", "ROOT")
NewDir.Path = WebSiteDirectory
NewDir.AccessRead = true
NewDir.AppFriendlyName = "应用程序" & WebSiteInfo
NewDir.AppCreate True
NewDir.AccessScript = True
Err.Clear
NewDir.SetInfo
If (Err.Number <> 0) Then
response.write "主目录创建时出错."
response.end
End If
If StartOrStop = True Then
Err.Clear
Set NewWebServer = GetObject("IIS://" & Computer & "/w3svc/" & SiteNum)
NewWebServer.Start
If Err.Number <> 0 Then
response.write "启动站点时出错!"
response.end
Err.Clear
End If
End If
response.write "站点创建成功,站点编号为:"& SiteNum &" ,域名为:"& HostName
End Function
使用ASP启动/停止指定WEB站点
'=============================================================
'函数介绍:使用ASP启动/停止指定WEB站点
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:AdminWebSite(Computer,WebSiteNum,DoWhat)
'用法:AdminWebSite(计算机名称,站点编号,启动/停止)
'例:启动127.0.0.1计算机上站点编号为1的站点
'AdminWebSite "127.0.0.1","1",1
'例:停止127.0.0.1计算机上站点编号为1的站点
'AdminWebSite "127.0.0.1","1",0
'=============================================================
Function AdminWebSite(Computer,WebSiteNum,DoWhat)
On Error Resume Next
Set objServer = GetObject("IIS://" & Computer & "/W3SVC/" & WebSiteNum)
If Err.Number <> 0 Then
Response.Write Now & ". 错误码: " & Hex(Err)& " - " & "无法开启指定站点
"
End If
if Dowhat=1 then
'使用Start启动站点
objServer.Start
If Err.Number <> 0 Then
Response.Write "无法启动指定Web站点
"
else
Response.Write "已经启动指定Web站点
"
End If
elseif DoWhat=0 then
'使用Stop停止站点
objServer.Stop
If Err.Number <> 0 Then
Response.Write "无法停止指定Web站点
"
else
Response.Write "已经停止指定Web站点
"
End If
end if
End Function
使用ASP列出服务器WEB站点信息
'=============================================================
'函数介绍:列出当前服务器WEB站点信息
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:ListWebSite (Computer,Num)
'用法:ListWebSite (计算机名称,显示站点数量)
'例:显示127.0.0.1计算机上1000个站点信息
'ListWebSite "127.0.0.1","1000"
'=============================================================
Function ListWebSite(Computer,Num)
On Error Resume Next
Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&i)
for i=0 to Num
Err.Clear
if Err.Number=0 then
response.write "
以下显示为计算机:"&Computer&"上所有站点信息
"ShowWebSite = SiteObj.Get("ServerBindings") '获得站点IP地址:端口:主机头
Info=split(ShowWebSite(0),":")
response.write "站点编号:"&i&"
"
response.write "站点IP地址:"&Info(0)&"
"
response.write "站点端口:"&Info(1)&"
"
response.write "站点主机头:"&Info(2)&"
"
end if
next
set SiteOjb=nothing
End Function
使用ASP删除指定IIS站点
'=============================================================
'函数介绍:删除指定IIS站点
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:DelWebSite (Computer,SiteNum)
'用法:DelWebSite 计算机名,站点编号
'例:DelWebSite "127.0.0.1","2"
'=============================================================
Function DelWebSite(Computer,SiteNum)
Set W3SVC = GetObject("IIS://"&Computer&"/w3svc")
W3SVC.delete "IIsWebServer",SiteNum
response.write "删除成功!"
End Function
通过ASP管理NT帐号
'=============================================================
'函数介绍:通过ASP管理NT帐号
'本函数使用ADSI,需要Administrators组用户权限
'=============================================================
'填加用户
'函数用法:AddUser(Computer,UserName,PassWord,FullName,Info)
'参数:计算机名,帐号名称,帐号密码,帐号全名,帐号说明
'例:AddUser "127.0.0.1","Test","Test","测试管理员帐号","本帐号通过ASP填加"
'修改指定用户基本信息
'函数用法:EditUser(Computer,UserName,OldPassWord,PassWord,FullName,Info)
'参数:计算机名,帐号名称,帐号密码,帐号全名,帐号说明
'例:EditUser "127.0.0.1","Test","Test2","测试管理员帐号修改","本帐号通过ASP修改过"
'删除指定用户
'函数用法:DelUser(Computer,UserName)
'参数:计算机名,用户名'
'例:DelUser "127.0.0.1","Test"
=============================================================
Function AddUser(Computer,UserName,PassWord,FullName,Info)
'执行创建帐号命令
Set ComputerObj = GetObject("WinNT://"&Computer)
Set NewUser = ComputerObj.Create( "User" , UserName )
NewUser.SetInfo
'进行帐号设置
NewUser.SetPassword ( PassWord ) '帐号密码
NewUser.FullName = FullName '帐号全名
NewUser.Description = Info '帐号说明
NewUser.UserFlags = &H10000 '&H20000(使用者下次登入时须变更密码) &H0040(使用者不得变更密码) &H10000(密码永久正确) &H0002(帐户暂时停用)
NewUser.SetInfo
response.write "帐号"&UserName&"创建成功!"
Set ComputerObj=nothing
End Function
Function EditUser(Computer,UserName,OldPassWord,PassWord,FullName,Info)
'读取用户信息
Set ChangeUserObj = GetObject("WinNT://"&Computer&"/"&UserName&",User")
'修改帐号密码
if PassWord<>"" then
ChangeUserObj.SetPassword PassWord
response.write "帐号密码修改成功!
"
end if
'修改帐号全名
if FullName<>"" then
UserFullName = ChangeUserObj.get("FullName")
ChangeUserObj.FullName = FullName
ChangeUserObj.SetInfo
response.write "帐号全名修改成功!
"
end if
'修改帐号说明
if Info<>"" then
UserFullName = ChangeUserObj.get("Description")
ChangeUserObj.Description = Info
ChangeUserObj.SetInfo
response.write "帐号说明修改成功!
"
end if
Set ChangeUserObj=nothing
End Function
Function DelUser(Computer,UserName)
Set DelUserObj = GetObject("WinNT://"&Computer&"/"&UserName)
If Err = &H800401E4 Then
Response.Write "用户"&UserName&"不存在"
Response.End
End If
Set DelObj = GetObject(DelUserObj.Parent)
DelObj.Delete "User", DelUserObj.Name
Set DelUserObj = Nothing
Set DelObj = Nothing
Response.Write "删除成功"
End Function
使用ASP控制指定站点解析脚本语言函数
Function AdminAegis(Computer,SiteNum)
Set IIsWebServiceObj = GetObject("IIS://"&Computer&"/W3SVC/"&SiteNum)
dim Aegis(1)
Aegis(0)=".asp,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE"
'Aegis(1)=".aspx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG"
'解析其它文件请同样使用Aegis(Num)=""这种格式,记得要将dim Aegis(Num)定义
'.htw,C:\WINNT\system32\webhits.dll,3,GET,HEAD,POST
'.ida,C:\WINNT\system32\idq.dll,7,GET,HEAD,POST
'.idq,C:\WINNT\system32\idq.dll,7,GET,HEAD,POST
'.asp,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.cer,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.cdx,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.asa,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.idc,C:\WINNT\system32\inetsrv\httpodbc.dll,5,GET,POST
'.shtm C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST
'.shtml C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST
'.stm C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST
'.asax C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.ascx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.ashx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.asmx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.aspx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.axd,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.vsdisco,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.rem,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.soap,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.config,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.cs,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.csproj,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.vb,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.vbproj,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.webinfo,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.licx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.resx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.resources,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
IIsWebServiceObj.ScriptMaps=Aegis
IIsWebServiceObj.SetInfo
'显示支持脚本语言
response.write "当前站点支持解析列表:
"
For ValueIndex = 0 To UBound(IIsWebServiceObj.ScriptMaps)
response.write IIsWebServiceObj.Get("ScriptMaps")(ValueIndex)
response.write "
"
Next
End Function
使用ASP列出NT用户组及用户
'=============================================================
'函数介绍:列出NT用户组及用户
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:ListGroup(Computer)
'用法:ListGroup(计算机名称)
'例:显示127.0.0.1计算机NT用户组及用户
'ListGroup "127.0.0.1"
'=============================================================
Function ListGroup(Computer)
response.write "
以下为计算机"&Computer&"系统用户组及用户列表
"Set ComputerObj = GetObject("WinNT://"&Computer)
ComputerObj.Filter = Array("Group")
For Each Member in ComputerObj
Response.Write "用户组:"&Member.Name&"
"
ListUser Computer,Member.Name
Next
end Function
'列出指定用户组用户
Function ListUser(Computer,Group)
Set UserObj = GetObject("WinNT://"&Computer&"/"&Group)
For Each Member in UserObj.Members
Response.write " 组中用户:"&Member.Name &"
"
Next
End Function
%>
25.将文字转化为它的源代码格式
<%
public function HtmlOut(str)
'将文字转化为它的源代码格式
dim guest
if isnull(str) or str="" then
htmlOut=str
exit function
end if
guest=str
guest=Replace(Guest," "," ")
guest=Replace(Guest," ","`nbsp;")
Guest=server.htmlencode(Guest)
guest=Replace(Guest,"`nbsp;"," ")
guest=Replace(Guest,vbcrlf,"
")
HtmlOut=guest
end function
%>
26.从数据库中提取内容生成下拉菜单
<%
public function OutOption(conn,tabel,style,value)
'从数据库中提取内容生成下拉菜单
'conn 为数据库联接 table为表名 style下接菜单样式
dim re,sql,selected
set re=server.CreateObject("ADODB.RECORDSET")
sql = "SELECT * FROM " & tabel & " ORDER BY value"
re.Open sql,conn
Response.Write ("" & vbCrlf)
set re=nothing
end function
%>
27.时间格式化函数
<%
Public Function FormatDT(dt, style)
'style=0 2000-10-10 下午 12:17:45
'style=1 2000-10-10 23:17:45
'style=2 2000-10-10 23:45
'style=3 00-10-10 23:45
'style=4 10-10 23:45
'style=5 2000-10-10
'style=6 00-10-10
'style=7 10-10
Dim nowdate, y, m, d, h, i, s, t, APM, hAPM
nowdate = dt
y = Year(nowdate)
m = Month(nowdate)
d = Day(nowdate)
h = Hour(nowdate)
i = Minute(nowdate)
s = Second(nowdate)
If h > 12 Then
APM = "下午 "
hAPM = CStr(CInt(h) Mod 12)
Else
APM = "上午 "
hAPM = h
End If
Select Case style
Case 0
t = y & "-" & m & "-" & d & " " & APM & hAPM & ":" & i & ":" & s
Case 1
t = y & "-" & m & "-" & d & " " & h & ":" & i & ":" & s
Case 2
t = y & "-" & m & "-" & d & " " & h & ":" & i
Case 3
t = Right(y, 2) & "-" & m & "-" & d & " " & h & ":" & i
Case 4
t = m & "-" & d & " " & h & ":" & i
Case 5
t = y & "-" & m & "-" & d
Case 6
t = Right(y, 2) & "-" & m & "-" & d
Case 7
t = m & "-" & d
End Select
FormatDT = t
End Function
%>
评论: 2 | 引用: 636 | 查看次数: 69589
发表评论