昨天一個(gè)朋友有個(gè)需求,是要通過(guò)WEB方式,修改IIS服務(wù)器上的時(shí)間,由于他的系統(tǒng)是asp 3.0下開(kāi)發(fā)的,所以本例子的代碼是ASP的,不是asp.net,但是本人寫(xiě)這個(gè)文章是想拋磚引玉,畢竟編寫(xiě)程序關(guān)鍵的不是語(yǔ)言,更重要的是一種思想,把程序語(yǔ)言理解為一種工具,把編程思想理解為解決問(wèn)題的思路和方法,那么編寫(xiě)出來(lái)的程序就是:利用“工具”按照解決問(wèn)題的“思想”去解決一個(gè)問(wèn)題。
首先,要感謝網(wǎng)友“小虎”,我是在網(wǎng)上看了他寫(xiě)的一篇關(guān)于用VB 6.0編寫(xiě)DLL組件FOR ASP的文章改寫(xiě)的,他的DLL代碼只實(shí)現(xiàn)了改寫(xiě)小時(shí)和分鐘,我增加了年、月、日、秒的修改。
首先,在VB 6.0中建立一個(gè)ActiveX Dll工程項(xiàng)目,信息如下:
工程名稱: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'由李錫遠(yuǎn)修改 修改日期:2006-08-31 修改項(xiàng)目:增加對(duì)年、月、日、秒的操作
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
78'SystemTime.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的文件。
關(guān)于DLL的注冊(cè),通常VB在本機(jī)上編譯后,會(huì)自動(dòng)將DLL注冊(cè);但如果你要放到IIS服務(wù)器上,請(qǐng)使用如下方法:
1、將systimeset.dll拷貝到c:/WINDOWS/system32下;
2、在開(kāi)始菜單的運(yùn)行里面輸入:regsvr32 systimeset.dll (敲回車(chē)啊)
3、因?yàn)樾薷姆?wù)器的時(shí)間,INTERNET來(lái)賓帳戶不具有該權(quán)限,設(shè)立權(quán)限請(qǐng)打開(kāi)控制面版中的“管理工具”,然后打開(kāi)“本地安全策略”--“用戶權(quán)力指派”,雙擊“更改系統(tǒng)時(shí)間”,在彈出的對(duì)話框中點(diǎn)“添加用戶或組”,將INETNET來(lái)賓帳戶加入進(jìn)來(lái)。
4、一切完畢后,將IIS服務(wù)重新啟動(dòng)一次。
在上面的設(shè)置完畢后,使用systimeset.dll組件的ASP代碼頁(yè)面如下:
1<% @language="vbscr 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
以上是所有實(shí)現(xiàn)的代碼,有問(wèn)題可以加我QQ:17020415
將上面的ASP代碼頁(yè)面粘貼到一個(gè)空的ASP文件中,然后在IIS中將站點(diǎn)設(shè)置好就可以了。(設(shè)置IIS虛擬目錄也可以的。)
http://www.survivalescaperooms.com/lixyvip/archive/2006/09/02/492693.html
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注