Username: Password:

用asp+dll实现web方式修改服务器时间_asp技巧
来源:网页教学网作者:未知 发布时间:2007-12-11 06:31:25

昨天一个朋友有个需求,是要通过WEB方式,修改IIS服务器上的时间,由于他的系统是ASP 3.0下研发的,所以本例子的代码是ASP的,不是ASP.NET,但是本人写这个文章是想抛砖引玉,毕竟编写程式关键的不是语言,更重要的是一种思想,把程式语言理解为一种工具,把编程思想理解为解决问题的思路和方法,那么编写出来的程式就是:利用“工具”按照解决问题的“思想”去解决一个问题。

首先,要感谢网友“小虎”,我是在网上看了他写的一篇关于用VB 6.0编写DLL组件FOR ASP的文章改写的,他的DLL代码只实现了改写小时和分钟,我增加了年、月、日、秒的修改。

首先,在VB 6.0中建立一个ActiveX Dll工程项目,信息如下:

工程名称:systimeset
类模块名称:timeset

VB 6.0的类模块代码如下:


 1Option Explicit
 2Private SystemTime As SystemTime
 3Private Declare Function SetSystemTime()Function SetSystemTime Lib "kernel32" (lpSystemTime As SystemTime) As Long
 4Private Type SystemTime
 5        wYear As Integer
 6        wMonth As Integer
 7        wDayOfWeek As Integer
 8        wDay As Integer
 9        wHour As Integer
10        wMinute As Integer
11        wSecond As Integer
12        wMilliseconds As Integer
13End Type
14
15Dim tmp
16
17Private m_Hour As Integer
18Private m_Minute As Integer
19Private m_Year As Integer
20Private m_Month As Integer
21Private m_Day As Integer
22Private m_Second As Integer
23
24由李锡远修改     修改日期:2006-08-31     修改项目:增加对年、月、日、秒的操作
25--------------------
26年
27Public Property Get()Property Get Year() As Integer
28Year = m_Year
29End Property
30Public Property Let()Property Let Year(tmp_Year As Integer)
31m_Year = tmp_Year
32End Property
33--------------------
34月
35Public Property Get()Property Get Month() As Integer
36Month = m_Month
37End Property
38Public Property Let()Property Let Month(tmp_Month As Integer)
39m_Month = tmp_Month
40End Property
41--------------------
42日
43Public Property Get()Property Get Day() As Integer
44Day = m_Day
45End Property
46Public Property Let()Property Let Day(tmp_Day As Integer)
47m_Day = tmp_Day
48End Property
49--------------------
50秒
51Public Property Get()Property Get Second() As Integer
52Second = m_Second
53End Property
54Public Property Let()Property Let Second(tmp_Second As Integer)
55m_Second = tmp_Second
56End Property
57
58
59
60Public Property Get()Property Get Hour() As Integer
61Hour = m_Hour
62End Property
63Public Property Let()Property Let Hour(tmp_Hour As Integer)
64m_Hour = tmp_Hour
65End Property
66Public Property Get()Property Get Minute() As Integer
67Minute = m_Minute
68End Property
69Public Property Let()Property Let Minute(tmp_Minute As Integer)
70m_Minute = tmp_Minute
71End Property
72
73
74
75
76Public Function setup()Function setup() As Integer
77SystemTime.wDay = Day
78SystemTime.wDayOfWeek = 1
79SystemTime.wMilliseconds = 0
80SystemTime.wMonth = Month
81SystemTime.wSecond = Second
82SystemTime.wYear = Year
83SystemTime.wHour = Hour
84SystemTime.wMinute = Minute
85setup = SetSystemTime(SystemTime)
86
87End Function
88
将其编译为systimeset.dll的文档。

关于DLL的注册,通常VB在本机上编译后,会自动将DLL注册;但假如您要放到IIS服务器上,请使用如下方法:
1、将systimeset.dll拷贝到c:\WINDOWS\system32下;
2、在开始菜单的运行里面输入:regsvr32 systimeset.dll     (敲回车啊)
3、因为修改服务器的时间,INTERNET来宾帐户不具备该权限,设立权限请打开控制面版中的“管理工具”,然后打开“本地安全策略”--“用户权力指派”,双击“更改系统时间”,在弹出的对话框中点“添加用户或组”,将INETNET来宾帐户加入进来。
4、一切完毕后,将IIS服务重新启动一次。


在上面的配置完毕后,使用systimeset.dll组件的ASP代码页面如下:


 1<% @language="vbscript" %>
 2<%
 3function SetTime(strYear,strMonth,strDay)
 4response.Expires=0
 5set obj=server.createobject("systimeset.timeset")
 6    obj.Year=strYear
 7    obj.Month=strMonth
 8    obj.Day=strDay
 9    if Hour(now())-8>0 then
10    obj.Hour=Hour(now())-8
11    else
12    obj.Hour=8
13    end if
14    obj.Minute=Minute(now())
15    obj.Second=Second(now())
16    obj.setup
17
18set obj=Nothing
19end function
20
21if request("act")="modi" then
22    call SetTime(request.Form("strYear"),request.Form("strMonth"),request.Form
23
24("strDay"))
25end if
26%>
27


28 
29   
30     
33     
36     
39     
40   
41 
31
32size="8" />
37
38size="5" />

42

43
以上是任何实现的代码,有问题能够加我QQ:17020415

将上面的ASP代码页面粘贴到一个空的ASP文档中,然后在IIS中将站点配置好就能够了。(配置IIS虚拟目录也能够的。)

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅