用ASP+DLL实现WEB方式修改服务器时间

昨天一个朋友有个需求,是要通过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的类模块代码如下:

 1 None.gif Option   Explicit
 2 None.gif Private  SystemTime  As  SystemTime
 3 ExpandedBlockStart.gifContractedBlock.gif Private   Declare   Function SetSystemTime() Function SetSystemTime Lib "kernel32" (lpSystemTime As SystemTime) As Long
 4InBlock.gifPrivate Type SystemTime
 5InBlock.gif        wYear As Integer
 6InBlock.gif        wMonth As Integer
 7InBlock.gif        wDayOfWeek As Integer
 8InBlock.gif        wDay As Integer
 9InBlock.gif        wHour As Integer
10InBlock.gif        wMinute As Integer
11InBlock.gif        wSecond As Integer
12InBlock.gif        wMilliseconds As Integer
13InBlock.gifEnd Type
14InBlock.gif
15InBlock.gifDim tmp
16InBlock.gif
17InBlock.gifPrivate m_Hour As Integer
18InBlock.gifPrivate m_Minute As Integer
19InBlock.gifPrivate m_Year As Integer
20InBlock.gifPrivate m_Month As Integer
21InBlock.gifPrivate m_Day As Integer
22InBlock.gifPrivate m_Second As Integer
23InBlock.gif
24InBlock.gif'由李锡远修改     修改日期:2006-08-31     修改项目:增加对年、月、日、秒的操作
25InBlock.gif'--------------------
26InBlock.gif'年
27ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Get()Property Get Year() As Integer
28InBlock.gifYear = m_Year
29ExpandedSubBlockEnd.gifEnd Property

30ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Let()Property Let Year(tmp_Year As Integer)
31InBlock.gifm_Year = tmp_Year
32ExpandedSubBlockEnd.gifEnd Property

33InBlock.gif'--------------------
34InBlock.gif'
35ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Get()Property Get Month() As Integer
36InBlock.gifMonth = m_Month
37ExpandedSubBlockEnd.gifEnd Property

38ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Let()Property Let Month(tmp_Month As Integer)
39InBlock.gifm_Month = tmp_Month
40ExpandedSubBlockEnd.gifEnd Property

41InBlock.gif'--------------------
42InBlock.gif'
43ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Get()Property Get Day() As Integer
44InBlock.gifDay = m_Day
45ExpandedSubBlockEnd.gifEnd Property

46ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Let()Property Let Day(tmp_Day As Integer)
47InBlock.gifm_Day = tmp_Day
48ExpandedSubBlockEnd.gifEnd Property

49InBlock.gif'--------------------
50InBlock.gif'
51ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Get()Property Get Second() As Integer
52InBlock.gifSecond = m_Second
53ExpandedSubBlockEnd.gifEnd Property

54ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Let()Property Let Second(tmp_Second As Integer)
55InBlock.gifm_Second = tmp_Second
56ExpandedSubBlockEnd.gifEnd Property

57InBlock.gif
58InBlock.gif
59InBlock.gif
60ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Get()Property Get Hour() As Integer
61InBlock.gifHour = m_Hour
62ExpandedSubBlockEnd.gifEnd Property

63ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Let()Property Let Hour(tmp_Hour As Integer)
64InBlock.gifm_Hour = tmp_Hour
65ExpandedSubBlockEnd.gifEnd Property

66ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Get()Property Get Minute() As Integer
67InBlock.gifMinute = m_Minute
68ExpandedSubBlockEnd.gifEnd Property

69ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Property Let()Property Let Minute(tmp_Minute As Integer)
70InBlock.gifm_Minute = tmp_Minute
71ExpandedSubBlockEnd.gifEnd Property

72InBlock.gif
73InBlock.gif
74InBlock.gif
75InBlock.gif
76ExpandedSubBlockStart.gifContractedSubBlock.gifPublic Function setup()Function setup() As Integer
77InBlock.gifSystemTime.wDay = Day
78InBlock.gif'SystemTime.wDayOfWeek = 1
79InBlock.gifSystemTime.wMilliseconds = 0
80InBlock.gifSystemTime.wMonth = Month
81InBlock.gifSystemTime.wSecond = Second
82InBlock.gifSystemTime.wYear = Year
83InBlock.gifSystemTime.wHour = Hour
84InBlock.gifSystemTime.wMinute = Minute
85InBlock.gifsetup = SetSystemTime(SystemTime)
86InBlock.gif
87ExpandedSubBlockEnd.gifEnd Function

88InBlock.gif

将其编译为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 None.gif < % @language = " vbscript "  % >
 2 None.gif < %
 3 None.gif function  SetTime(strYear,strMonth,strDay)
 4 None.gifresponse.Expires = 0
 5 None.gif set  obj = server.createobject( " systimeset.timeset " )
 6 None.gif    obj.Year = strYear
 7 None.gif    obj.Month = strMonth
 8 None.gif    obj.Day = strDay
 9 None.gif     if   Hour ( now ()) - 8 > 0   then
10 None.gif    obj.Hour = Hour ( now ()) - 8
11 None.gif     else
12 None.gif    obj.Hour = 8
13 None.gif     end   if
14 None.gif    obj.Minute = Minute ( now ())
15 None.gif    obj.Second = Second ( now ())
16 None.gif    obj.setup
17 None.gif
18 None.gif set  obj = Nothing
19 None.gif end function
20 None.gif
21 None.gif if  request( " act " ) = " modi "   then
22 None.gif     call  SetTime(request.Form( " strYear " ),request.Form( " strMonth " ),request.Form
23 None.gif
24 None.gif( " strDay " ))
25 None.gif end   if
26 None.gif% >
27 None.gif < form id = " form1 "  name = " form1 "  method = " post "  action = " ?act=modi " >
28 None.gif   < table width = " 290 "  border = " 0 " >
29 None.gif     < tr >
30 None.gif       < td width = " 77 " >< input name = " strYear "  type = " text "  id = " strYear "  value = " <%=Year(now())%> "  
31 None.gif
32 None.gifsize = " 8 "   /></ td >
33 None.gif       < td width = " 49 " >< input name = " strMonth "  type = " text "  id = " strMonth "  value = " <%=Month(now
34 None.gif
35 None.gif())% > "  size= " 5 "  /></td>
36 None.gif        < td width = " 48 " >< input name = " strDay "  type = " text "  id = " strDay "  value = " <%=Day(now())%> "  
37 None.gif
38 None.gifsize = " 5 "   /></ td >
39 None.gif       < td width = " 98 " >< input type = " submit "  name = " Submit "  value = " 修改日期 "   /></ td >
40 None.gif     </ tr >
41 None.gif   </ table >
42 None.gif </ form >
43 None.gif

以上是所有实现的代码,有问题可以加我QQ:17020415

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

下面附上源码打包下载:
完整源码和ASP文件

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值