Home > Web Front-end > JS Tutorial > Code to modify (set) system time and date using VBS

Code to modify (set) system time and date using VBS

高洛峰
Release: 2017-01-16 10:18:33
Original
1860 people have browsed it

那天跟别人聊到 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
Copy after login

比较有技术含量的方法是用 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
Copy after login

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

更多用VBS修改(设置)系统时间和日期的代码相关文章请关注PHP中文网!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template