昨天一个朋友有个需求,是要通过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的类模块代码如下:
首先,要感谢网友“小虎”,我是在网上看了他写的一篇关于用VB 6.0编写DLL组件FOR ASP的文章改写的,他的DLL代码只实现了改写小时和分钟,我增加了年、月、日、秒的修改。
首先,在VB 6.0中建立一个ActiveX Dll工程项目,信息如下:
工程名称:systimeset
类模块名称:timeset
VB 6.0的类模块代码如下:
1
Option Explicit
2
Private SystemTime As SystemTime
3
Private Declare Function SetSystemTime()Function SetSystemTime Lib "kernel32" (lpSystemTime As SystemTime) As Long
4
Private 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
13
End Type
14
15
Dim tmp
16
17
Private m_Hour As Integer
18
Private m_Minute As Integer
19
Private m_Year As Integer
20
Private m_Month As Integer
21
Private m_Day As Integer
22
Private m_Second As Integer
23
24
''由李锡远修改 修改日期:2006-08-31 修改项目:增加对年、月、日、秒的操作 Www@ @com
25
''--------------------
26
''年
27
Public Property Get()Property Get Year() As Integer
28
Year = m_Year
29
End Property
30
Public Property Let()Property Let Year(tmp_Year As Integer)
31
m_Year = tmp_Year
32
End Property
33
''--------------------
34
''月
35
Public Property Get()Property Get Month() As Integer
36
Month = m_Month
37
End Property
38
Public Property Let()Property Let Month(tmp_Month As Integer) ^com
39
m_Month = tmp_Month
40
End Property
41
''--------------------
42
''日
43
Public Property Get()Property Get Day() As Integer _com
44
Day = m_Day
45
End Property
46
Public Property Let()Property Let Day(tmp_Day As Integer)
47
m_Day = tmp_Day
48
End Property
49
''--------------------
50
''秒
51
Public Property Get()Property Get Second() As Integer
52
Second = m_Second
53
End Property
54
Public Property Let()Property Let Second(tmp_Second As Integer)
55
m_Second = tmp_Second
56
End Property
57
58
59
60
Public Property Get()Property Get Hour() As Integer
61
Hour = m_Hour
62
End Property
63
Public Property Let()Property Let Hour(tmp_Hour As Integer) Www^ ^com
64
m_Hour = tmp_Hour
65
End Property
66
Public Property Get()Property Get Minute() As Integer
67
Minute = m_Minute
68
End Property
69
Public Property Let()Property Let Minute(tmp_Minute As Integer) 中国站长_站,为中文网站提供动力
70
m_Minute = tmp_Minute
71
End Property
72
73
74
Www^ ^com
75
76
Public Function setup()Function setup() As Integer
77
SystemTime.wDay = Day
78
''SystemTime.wDayOfWeek = 1
79
SystemTime.wMilliseconds = 0
80
SystemTime.wMonth = Month
81
SystemTime.wSecond = Second
82
SystemTime.wYear = Year Www@ @com
83
SystemTime.wHour = Hour
84
SystemTime.wMinute = Minute
85
setup = SetSystemTime(SystemTime)
86
87
End Function
88
关于DLL的注册,通常VB在本机上编译后,会自动将DLL注册;但如果你要放到IIS服务器上,请使用如下方法:
1、将systimeset.dll拷贝到c:\WINDOWS\system32下;
2、在开始菜单的运行里面输入:regsvr32 systimeset.dll (敲回车啊)
3、因为修改服务器的时间,INTERNET来宾帐户不具有该权限,设立权限请打开控制面版中的“管理工具”,然后打开“本地安全策略”--“用户权力指派”,双击“更改系统时间”,在弹出的对话框中点“添加用户或组”,将INETNET来宾帐户加入进来。 ^com
4、一切完毕后,将IIS服务重新启动一次。
在上面的设置完毕后,使用systimeset.dll组件的ASP代码页面如下:
Option Explicit _com
2
Private SystemTime As SystemTime3

Private Declare Function SetSystemTime()Function SetSystemTime Lib "kernel32" (lpSystemTime As SystemTime) As Long 4
Private Type SystemTime5
wYear As Integer6
wMonth As Integer [中国站长站]
7
wDayOfWeek As Integer8
wDay As Integer9
wHour As Integer 中国站长_站,为中文网站提供动力 10
wMinute As Integer11
wSecond As Integer12
wMilliseconds As Integer 中.国站长站
13
End Type14

15
Dim tmp16

17
Private m_Hour As Integer 18
Private m_Minute As Integer19
Private m_Year As Integer20
Private m_Month As Integer
21
Private m_Day As Integer22
Private m_Second As Integer23

24
''由李锡远修改 修改日期:2006-08-31 修改项目:增加对年、月、日、秒的操作 Www@ @com 25
''--------------------26
''年27

Public Property Get()Property Get Year() As Integer 中国站.长.站
28
Year = m_Year29
End Property30

Public Property Let()Property Let Year(tmp_Year As Integer) 31
m_Year = tmp_Year32
End Property33
''--------------------34
''月 [中国站长站]
35

Public Property Get()Property Get Month() As Integer [中国站长站]
36
Month = m_Month37
End Property38

Public Property Let()Property Let Month(tmp_Month As Integer) ^com 39
m_Month = tmp_Month40
End Property41
''--------------------42
''日 Www^ ^com
43

Public Property Get()Property Get Day() As Integer _com 44
Day = m_Day45
End Property46

Public Property Let()Property Let Day(tmp_Day As Integer)
47
m_Day = tmp_Day48
End Property49
''--------------------50
''秒 51

Public Property Get()Property Get Second() As Integer ~com
52
Second = m_Second53
End Property54

Public Property Let()Property Let Second(tmp_Second As Integer) 55
m_Second = tmp_Second56
End Property57

58

59
60

Public Property Get()Property Get Hour() As Integer Www_ _com
61
Hour = m_Hour62
End Property63

Public Property Let()Property Let Hour(tmp_Hour As Integer) Www^ ^com 64
m_Hour = tmp_Hour65
End Property66

Public Property Get()Property Get Minute() As Integer 中国站长.站
67
Minute = m_Minute68
End Property69

Public Property Let()Property Let Minute(tmp_Minute As Integer) 中国站长_站,为中文网站提供动力 70
m_Minute = tmp_Minute71
End Property72

73

74
Www^ ^com 75

76

Public Function setup()Function setup() As Integer
77
SystemTime.wDay = Day78
''SystemTime.wDayOfWeek = 179
SystemTime.wMilliseconds = 0 ^com
80
SystemTime.wMonth = Month81
SystemTime.wSecond = Second82
SystemTime.wYear = Year Www@ @com 83
SystemTime.wHour = Hour84
SystemTime.wMinute = Minute85
setup = SetSystemTime(SystemTime)86
Www@ @com
87
End Function88

关于DLL的注册,通常VB在本机上编译后,会自动将DLL注册;但如果你要放到IIS服务器上,请使用如下方法:
1、将systimeset.dll拷贝到c:\WINDOWS\system32下;
2、在开始菜单的运行里面输入:regsvr32 systimeset.dll (敲回车啊)
3、因为修改服务器的时间,INTERNET来宾帐户不具有该权限,设立权限请打开控制面版中的“管理工具”,然后打开“本地安全策略”--“用户权力指派”,双击“更改系统时间”,在弹出的对话框中点“添加用户或组”,将INETNET来宾帐户加入进来。 ^com
4、一切完毕后,将IIS服务重新启动一次。
在上面的设置完毕后,使用systimeset.dll组件的ASP代码页面如下:
将其编译为systimeset.dll的文件。
1
<% @language="vbscript" %>
2
<% @com
3
function SetTime(strYear,strMonth,strDay)
4
response.Expires=0
5
set 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 _com
13
end if
14
obj.Minute=Minute(now())
15
obj.Second=Second(now())
16
obj.setup
17
18
set obj=Nothing
19
end function
20
21
if request("act")="modi" then
22
call SetTime(request.Form("strYear"),request.Form("strMonth"),request.Form
23
24
("strDay"))
25
end 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
32
size="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
38
size="5" /></td>
39
<td width="98"><input type="submit" name="Submit" value="修改日期" /></td>
40
</tr>
41
</table>
42
</form>
43
<% @language="vbscript" %>2
<% @com 3
function SetTime(strYear,strMonth,strDay)4
response.Expires=05
set obj=server.createobject("systimeset.timeset") 中.国.站.长.站
6
obj.Year=strYear7
obj.Month=strMonth8
obj.Day=strDay9
if Hour(now())-8>0 then 10
obj.Hour=Hour(now())-811
else12
obj.Hour=8 _com 13
end if14
obj.Minute=Minute(now())15
obj.Second=Second(now()) ^com
16
obj.setup17

18
set obj=Nothing19
end function20
Www_ _com
21
if request("act")="modi" then22
call SetTime(request.Form("strYear"),request.Form("strMonth"),request.Form 23

24
("strDay"))25
end if26
%> 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

32
size="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

38
size="5" /></td>39
<td width="98"><input type="submit" name="Submit" value="修改日期" /></td> _com
40
</tr>41
</table>42
</form>43

以上是所有实现的代码,有问题可以加我QQ:17020415 [中国站长站]
将上面的ASP代码页面粘贴到一个空的ASP文件中,然后在IIS中将站点设置好就可以了。(设置IIS虚拟目录也可以的。)
Www.
