杰网资源 Design By www.escxy.com
那天跟别人聊到 Y2K38 问题,于是想到一个恶作剧:用 VBS 把系统的时间修改到2038年1月19日3时14分07秒之后,这样某些依赖于 Unix 时间戳的程序就会出问题。那么怎样用 VBS 修改系统的时间呢?


最简单也是最没有技术含量的方法就是调用 cmd 的 date 和 time 命令:
复制代码 代码如下:
'Author: Demon
'Website: http://demon.tw
'Date : 2011/4/27
Dim WshShell
Set WshShell = CreateObject("wscript.Shell")
WshShell.Run "cmd.exe /c date 2038-01-19", 0
WshShell.Run "cmd.exe /c time 3:14:08", 0

比较有技术含量的方法是用 WMI 的 Win32_OperatingSystem 类的 SetDateTime 方法:
复制代码 代码如下:
'Author: Demon
'Website: http://demon.tw
'Date : 2011/4/27
dtmNewDateTime = "20380119031408.000000+480" 'UTC时间
strComputer = "."
Set objWMIService = GetObject("winmgmts:{(Systemtime)}\\" & strComputer & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objOS In colOSes
objOS.SetDateTime dtmNewDateTime
Next

Windows 7 在开启 UAC 的情况下需要管理员权限才能修改时间,一点也不好玩。

参考链接:Hey, Scripting Guy! How Can I Set the Date and Time on a Computer?

来自: http://demon.tw/programming/vbs-modify-system-time.html

标签:
VBS,系统时间,日期

杰网资源 Design By www.escxy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
杰网资源 Design By www.escxy.com