您好,欢迎访问一九零五行业门户网

用VBS修改(设置)系统时间和日期的代码

那天跟别人聊到 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 的情况下需要管理员权限才能修改时间,一点也不好玩。
更多用vbs修改(设置)系统时间和日期的代码。
其它类似信息

推荐信息