最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

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

日期:11-25    来源:中国设计秀    作者:cnwebshow.com

昨天一个朋友有个需求,是要通过WEB方式,修改IIS服务器上的时间,由于他的系统是asp 3.0下开发的,所以本例子的代码是ASP的,不是asp.net,但是本人写这个文章是想抛砖引玉,毕竟编写程序关键的不是语言,更重要的是一种思想,把程序语言理解为一种工具,把编程思想理解为解决问题的思路和方法,那么编写出来的程序就是:利用“工具”按照解决问题的“思想”去解决一个问题。ghX中国设计秀

首先,要感谢网友“小虎”,我是在网上看了他写的一篇关于用VB 6.0编写DLL组件FOR ASP的文章改写的,他的DLL代码只实现了改写小时和分钟,我增加了年、月、日、秒的修改。ghX中国设计秀

首先,在VB 6.0中建立一个ActiveX Dll工程项目,信息如下:ghX中国设计秀

工程名称:systimesetghX中国设计秀
类模块名称:timesetghX中国设计秀

VB 6.0的类模块代码如下:ghX中国设计秀

ghX中国设计秀
 1Option ExplicitghX中国设计秀
 2PRivate SystemTime As SystemTimeghX中国设计秀
 3Private Declare Function SetSystemTime()Function SetSystemTime Lib "kernel32" (lpSystemTime As SystemTime) As LongghX中国设计秀
 4Private Type SystemTimeghX中国设计秀
 5        wYear As IntegerghX中国设计秀
 6        wMonth As IntegerghX中国设计秀
 7        wDayOfWeek As IntegerghX中国设计秀
 8        wDay As IntegerghX中国设计秀
 9        wHour As IntegerghX中国设计秀
10        wMinute As IntegerghX中国设计秀
11        wSecond As IntegerghX中国设计秀
12        wMilliseconds As IntegerghX中国设计秀
13End TypeghX中国设计秀
14ghX中国设计秀
15Dim tmpghX中国设计秀
16ghX中国设计秀
17Private m_Hour As IntegerghX中国设计秀
18Private m_Minute As IntegerghX中国设计秀
19Private m_Year As IntegerghX中国设计秀
20Private m_Month As IntegerghX中国设计秀
21Private m_Day As IntegerghX中国设计秀
22Private m_Second As IntegerghX中国设计秀
23ghX中国设计秀
24'由李锡远修改     修改日期:2006-08-31     修改项目:增加对年、月、日、秒的操作ghX中国设计秀
25'--------------------ghX中国设计秀
26'年ghX中国设计秀
27Public Property Get()Property Get Year() As IntegerghX中国设计秀
28Year = m_YearghX中国设计秀
29End PropertyghX中国设计秀
30Public Property Let()Property Let Year(tmp_Year As Integer)ghX中国设计秀
31m_Year = tmp_YearghX中国设计秀
32End PropertyghX中国设计秀
33'--------------------ghX中国设计秀
34'月ghX中国设计秀
35Public Property Get()Property Get Month() As IntegerghX中国设计秀
36Month = m_MonthghX中国设计秀
37End PropertyghX中国设计秀
38Public Property Let()Property Let Month(tmp_Month As Integer)ghX中国设计秀
39m_Month = tmp_MonthghX中国设计秀
40End PropertyghX中国设计秀
41'--------------------ghX中国设计秀
42'日ghX中国设计秀
43Public Property Get()Property Get Day() As IntegerghX中国设计秀
44Day = m_DayghX中国设计秀
45End PropertyghX中国设计秀
46Public Property Let()Property Let Day(tmp_Day As Integer)ghX中国设计秀
47m_Day = tmp_DayghX中国设计秀
48End PropertyghX中国设计秀
49'--------------------ghX中国设计秀
50'秒ghX中国设计秀
51Public Property Get()Property Get Second() As IntegerghX中国设计秀
52Second = m_SecondghX中国设计秀
53End PropertyghX中国设计秀
54Public Property Let()Property Let Second(tmp_Second As Integer)ghX中国设计秀
55m_Second = tmp_SecondghX中国设计秀
56End PropertyghX中国设计秀
57ghX中国设计秀
58ghX中国设计秀
59ghX中国设计秀
60Public Property Get()Property Get Hour() As IntegerghX中国设计秀
61Hour = m_HourghX中国设计秀
62End PropertyghX中国设计秀
63Public Property Let()Property Let Hour(tmp_Hour As Integer)ghX中国设计秀
64m_Hour = tmp_HourghX中国设计秀
65End PropertyghX中国设计秀
66Public Property Get()Property Get Minute() As IntegerghX中国设计秀
67Minute = m_MinuteghX中国设计秀
68End PropertyghX中国设计秀
69Public Property Let()Property Let Minute(tmp_Minute As Integer)ghX中国设计秀
70m_Minute = tmp_MinuteghX中国设计秀
71End PropertyghX中国设计秀
72ghX中国设计秀
73ghX中国设计秀
74ghX中国设计秀
75ghX中国设计秀
76Public Function setup()Function setup() As IntegerghX中国设计秀
77SystemTime.wDay = DayghX中国设计秀
78'SystemTime.wDayOfWeek = 1ghX中国设计秀
79SystemTime.wMilliseconds = 0ghX中国设计秀
80SystemTime.wMonth = MonthghX中国设计秀
81SystemTime.wSecond = SecondghX中国设计秀
82SystemTime.wYear = YearghX中国设计秀
83SystemTime.wHour = HourghX中国设计秀
84SystemTime.wMinute = MinuteghX中国设计秀
85setup = SetSystemTime(SystemTime)ghX中国设计秀
86ghX中国设计秀
87End FunctionghX中国设计秀
88ghX中国设计秀
将其编译为systimeset.dll的文件。ghX中国设计秀

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

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

ghX中国设计秀
 1<% @language="vbscript" %>ghX中国设计秀
 2<%ghX中国设计秀
 3function SetTime(strYear,strMonth,strDay)ghX中国设计秀
 4response.Expires=0ghX中国设计秀
 5set obj=server.createobject("systimeset.timeset")ghX中国设计秀
 6    obj.Year=strYearghX中国设计秀
 7    obj.Month=strMonthghX中国设计秀
 8    obj.Day=strDayghX中国设计秀
 9    if Hour(now())-8>0 thenghX中国设计秀
10    obj.Hour=Hour(now())-8ghX中国设计秀
11    elseghX中国设计秀
12    obj.Hour=8ghX中国设计秀
13    end ifghX中国设计秀
14    obj.Minute=Minute(now())ghX中国设计秀
15    obj.Second=Second(now())ghX中国设计秀
16    obj.setupghX中国设计秀
17ghX中国设计秀
18set obj=NothingghX中国设计秀
19end functionghX中国设计秀
20ghX中国设计秀
21if request("act")="modi" thenghX中国设计秀
22    call SetTime(request.Form("strYear"),request.Form("strMonth"),request.FormghX中国设计秀
23ghX中国设计秀
24("strDay"))ghX中国设计秀
25end ifghX中国设计秀
26%>ghX中国设计秀
27<form id="form1" name="form1" method="post" action="?act=modi">ghX中国设计秀
28  <table width="290" border="0">ghX中国设计秀
29    <tr>ghX中国设计秀
30      <td width="77"><input name="strYear" type="text" id="strYear" value="<%=Year(now())%>" ghX中国设计秀
31ghX中国设计秀
32size="8" /></td>ghX中国设计秀
33      <td width="49"><input name="strMonth" type="text" id="strMonth" value="<%=Month(nowghX中国设计秀
34ghX中国设计秀
35())%>" size="5" /></td>ghX中国设计秀
36      <td width="48"><input name="strDay" type="text" id="strDay" value="<%=Day(now())%>" ghX中国设计秀
37ghX中国设计秀
38size="5" /></td>ghX中国设计秀
39      <td width="98"><input type="submit" name="Submit" value="修改日期" /></td>ghX中国设计秀
40    </tr>ghX中国设计秀
41  </table>ghX中国设计秀
42</form>ghX中国设计秀
43ghX中国设计秀
以上是所有实现的代码,有问题可以加我QQ:17020415

本文引用地址:/bc/article_46470.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明