网络编程 
首页 > 网络编程 > 浏览文章

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

(编辑:jimmy 日期: 2024/10/8 浏览:3 次 )
昨天一个朋友有个需求,是要通过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的类模块代码如下:
复制代码 代码如下:
Option Explicit
Private SystemTime As SystemTime
Private Declare Function SetSystemTime()Function SetSystemTime Lib "kernel32" (lpSystemTime As SystemTime) As Long
Private Type SystemTime
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
End Type

Dim tmp

Private m_Hour As Integer
Private m_Minute As Integer
Private m_Year As Integer
Private m_Month As Integer
Private m_Day As Integer
Private m_Second As Integer

'由李锡远修改     修改日期:2006-08-31     修改项目:增加对年、月、日、秒的操作
'--------------------
'年
Public Property Get()Property Get Year() As Integer
Year = m_Year
End Property
Public Property Let()Property Let Year(tmp_Year As Integer)
m_Year = tmp_Year
End Property
'--------------------
'月
Public Property Get()Property Get Month() As Integer
Month = m_Month
End Property
Public Property Let()Property Let Month(tmp_Month As Integer)
m_Month = tmp_Month
End Property
'--------------------
'日
Public Property Get()Property Get Day() As Integer
Day = m_Day
End Property
Public Property Let()Property Let Day(tmp_Day As Integer)
m_Day = tmp_Day
End Property
'--------------------
'秒
Public Property Get()Property Get Second() As Integer
Second = m_Second
End Property
Public Property Let()Property Let Second(tmp_Second As Integer)
m_Second = tmp_Second
End Property



Public Property Get()Property Get Hour() As Integer
Hour = m_Hour
End Property
Public Property Let()Property Let Hour(tmp_Hour As Integer)
m_Hour = tmp_Hour
End Property
Public Property Get()Property Get Minute() As Integer
Minute = m_Minute
End Property
Public Property Let()Property Let Minute(tmp_Minute As Integer)
m_Minute = tmp_Minute
End Property

Public Function setup()Function setup() As Integer
SystemTime.wDay = Day
'SystemTime.wDayOfWeek = 1
SystemTime.wMilliseconds = 0
SystemTime.wMonth = Month
SystemTime.wSecond = Second
SystemTime.wYear = Year
SystemTime.wHour = Hour
SystemTime.wMinute = Minute
setup = SetSystemTime(SystemTime)
End Function

将其编译为systimeset.dll的文件。

关于DLL的注册,通常VB在本机上编译后,会自动将DLL注册;但如果你要放到IIS服务器上,请使用如下方法:
1、将systimeset.dll拷贝到c:\WINDOWS\system32下;
2、在开始菜单的运行里面输入:regsvr32 systimeset.dll     (敲回车啊)
3、因为修改服务器的时间,INTERNET来宾帐户不具有该权限,设立权限请打开控制面版中的“管理工具”,然后打开“本地安全策略”--“用户权力指派”,双击“更改系统时间”,在弹出的对话框中点“添加用户或组”,将INETNET来宾帐户加入进来。
4、一切完毕后,将IIS服务重新启动一次。


在上面的设置完毕后,使用systimeset.dll组件的ASP代码页面如下:

复制代码 代码如下:
<% @language="vbscript" %>
<%
function SetTime(strYear,strMonth,strDay)
response.Expires=0
set obj=server.createobject("systimeset.timeset")
    obj.Year=strYear
   obj.Month=strMonth
    obj.Day=strDay
   if Hour(now())-8>0 then
    obj.Hour=Hour(now())-8
    else
    obj.Hour=8
    end if
    obj.Minute=Minute(now())
    obj.Second=Second(now())
    obj.setup

set obj=Nothing
end function

if request("act")="modi" then
    call SetTime(request.Form("strYear"),request.Form("strMonth"),request.Form

("strDay"))
end if
%>
<form id="form1" name="form1" method="post" action="?act=modi">
  <table width="290" border="0">
    <tr>
      <td width="77"><input name="strYear" type="text" id="strYear" value="<%=Year(now())%>" size="8" /></td>
     <td width="49"><input name="strMonth" type="text" id="strMonth" value="<%=Month(now())%>" size="5" /></td>
     <td width="48"><input name="strDay" type="text" id="strDay" value="<%=Day(now())%>" size="5" /></td>
     <td width="98"><input type="submit" name="Submit" value="修改日期" /></td>
   </tr>
 </table>
</form>

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

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


上一篇:Asp事务处理
下一篇:用sql设置access的默认值
一句话新闻
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?