昨天一个朋友有个需求,是要通过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<form id=”form1″ name=”form1″ method=”post” action=”?act=modi”>
28 <table width=”290″ border=”0″>
29 <tr>
30 <td width=”77″><input name=”stryear” type=”text” id=”stryear” value=”<%=year(now())%>”
31
32size=”8″ /></td>
33 <td width=”49″><input name=”strmonth” type=”text” id=”strmonth” value=”<%=month(now
34
35())%>” size=”5″ /></td>
36 <td width=”48″><input name=”strday” type=”text” id=”strday” value=”<%=day(now())%>”
37
38size=”5″ /></td>
39 <td width=”98″><input type=”submit” name=”submit” value=”修改日期” /></td>
40 </tr>
41 </table>
42</form>
43
以上是所有实现的代码,有问题可以加我qq:17020415
将上面的asp代码页面粘贴到一个空的asp文件中,然后在iis中将站点设置好就可以了。(设置iis虚拟目录也可以的。)