<p> 昨天一个朋友有个需求,是要通过WEB方式,修改IIS服务器上的时间,由于他的系统是ASP 3.0下开发的,所以本例子的代码是ASP的,不是ASP.NET,但是本人写这个文章是想抛砖引玉,毕竟编写程序关键的不是语言,更重要的是一种思想,把程序语言理解为一种工具,把编程思想理解为解决问题的思路和方法,那么编写出来的程序就是:利用“工具”按照解决问题的“思想”去解决一个问题。</p><p> 首先,要感谢网友“小虎”,我是在网上看了他写的一篇关于用VB 6.0编写DLL组件FOR ASP的文章改写的,他的DLL代码只实现了改写小时和分钟,我增加了年、月、日、秒的修改。</p><p> 首先,在VB 6.0中建立一个ActiveX Dll工程项目,信息如下:</p><p> 工程名称:systimeset</p><p> 类模块名称:timeset</p><p> VB 6.0的类模块代码如下:</p><code>1Option Explicit<br />2Private SystemTime As SystemTime<br />3Private Declare Function SetSystemTime()Function SetSystemTime Lib "kernel32" (lpSystemTime As SystemTime) As Long<br />4Private Type SystemTime<br />5 wYear As Integer<br />6 wMonth As Integer<br />7 wDayOfWeek As Integer<br />8 wDay As Integer<br />9 wHour As Integer<br />10 wMinute As Integer<br />11 wSecond As Integer<br />12 wMilliseconds As Integer<br />13End Type<br />14<br />15Dim tmp<br />16<br />17Private m_Hour As Integer<br />18Private m_Minute As Integer<br />19Private m_Year As Integer<br />20Private m_Month As Integer<br />21Private m_Day As Integer<br />22Private m_Second As Integer<br />23<br />24'由李锡远修改 修改日期:2006-08-31 修改项目:增加对年、月、日、秒的操作<br />25'--------------------<br />26'年<br />27Public Property Get()Property Get Year() As Integer<br />28Year = m_Year<br />29End Property<br />30Public Property Let()Property Let Year(tmp_Year As Integer)<br />31m_Year = tmp_Year<br />32End Property<br />33'--------------------<br />34'月<br />35Public Property Get()Property Get Month() As Integer<br />36Month = m_Month<br />37End Property<br />38Public Property Let()Property Let Month(tmp_Month As Integer)<br />39m_Month = tmp_Month<br />40End Property<br />41'--------------------<br />42'日<br />43Public Property Get()Property Get Day() As Integer<br />44Day = m_Day<br />45End Property<br />46Public Property Let()Property Let Day(tmp_Day As Integer)<br />47m_Day = tmp_Day<br />48End Property<br />49'--------------------<br />50'秒<br />51Public Property Get()Property Get Second() As Integer<br />52Second = m_Second<br />53End Property<br />54Public Property Let()Property Let Second(tmp_Second As Integer)<br />55m_Second = tmp_Second<br />56End Property<br />57<br />58<br />59<br />60Public Property Get()Property Get Hour() As Integer<br />61Hour = m_Hour<br />62End Property<br />63Public Property Let()Property Let Hour(tmp_Hour As Integer)<br />64m_Hour = tmp_Hour<br />65End Property<br />66Public Property Get()Property Get Minute() As Integer<br />67Minute = m_Minute<br />68End Property<br />69Public Property Let()Property Let Minute(tmp_Minute As Integer)<br />70m_Minute = tmp_Minute<br />71End Property<br />72<br />73<br />74<br />75<br />76Public Function setup()Function setup() As Integer<br />77SystemTime.wDay = Day<br />78'SystemTime.wDayOfWeek = 1<br />79SystemTime.wMilliseconds = 0<br />80SystemTime.wMonth = Month<br />81SystemTime.wSecond = Second<br />82SystemTime.wYear = Year<br />83SystemTime.wHour = Hour<br />84SystemTime.wMinute = Minute<br />85setup = SetSystemTime(SystemTime)<br />86<br />87End Function<br />88</code><p> 关于DLL的注册,通常VB在本机上编译后,会自动将DLL注册;但如果你要放到IIS服务器上,请使用如下方法:</p>
<p> </p>
<p> 1、将systimeset.dll拷贝到c:WINDOWSsystem32下;</p><p> 2、在开始菜单的运行里面输入:regsvr32 systimeset.dll (敲回车啊)</p><p> 3、因为修改服务器的时间,INTERNET来宾帐户不具有该权限,设立权限请打开控制面版中的“管理工具”,然后打开“本地安全策略”--“用户权力指派”,双击“更改系统时间”,在弹出的对话框中点“添加用户或组”,将INETNET来宾帐户加入进来。</p><p> 4、一切完毕后,将IIS服务重新启动一次。</p><p> 在上面的设置完毕后,使用systimeset.dll组件的ASP代码页面如下:</p><p> 将其编译为systimeset.dll的文件。</p><code>1<% @language="vbscript" %><br />2<%<br />3function SetTime(strYear,strMonth,strDay)<br />4response.Expires=0<br />5set obj=server.createobject("systimeset.timeset")<br />6 obj.Year=strYear<br />7 obj.Month=strMonth<br />8 obj.Day=strDay<br />9 if Hour(now())-8>0 then<br />10 obj.Hour=Hour(now())-8<br />11 else<br />12 obj.Hour=8<br />13 end if<br />14 obj.Minute=Minute(now())<br />15 obj.Second=Second(now())<br />16 obj.setup<br />17<br />18set obj=Nothing<br />19end function<br />20<br />21if request("act")="modi" then<br />22 call SetTime(request.Form("strYear"),request.Form("strMonth"),request.Form<br />23<br />24("strDay"))<br />25end if<br />26%><br />27<form id="form1" name="form1" method="post" action="?act=modi"><br />28 <table width="290" border="0"><br />29 <tr><br />30 <td width="77"><input name="strYear" type="text" id="strYear" value="<%=Year(now())%>"<br />31<br />32size="8" /></td><br />33 <td width="49"><input name="strMonth" type="text" id="strMonth" value="<%=Month(now<br />34<br />35())%>" size="5" /></td><br />36 <td width="48"><input name="strDay" type="text" id="strDay" value="<%=Day(now())%>"<br />37<br />38size="5" /></td><br />39 <td width="98"><input type="submit" name="Submit" value="修改日期" /></td><br />40 </tr><br />41 </table><br />42</form><br />43</code><p> 以上是所有实现的代码,有问题可以加我QQ:17020415</p></p><p> 将上面的ASP代码页面粘贴到一个空的ASP文件中,然后在IIS中将站点设置好就可以了。(设置IIS虚拟目录也可以的。)</p></p>