Code for modifying (setting) the system time and date with VBS

Source: Internet
Author: User

I talked to others about Y2K38 that day, so I thought of a prank: I used VBS to change the system time after 03:14:07 on January 1, January 19, 2038, so that some programs dependent on Unix timestamps may have problems. So how can we use VBS to modify the system time?

The simplest and least technical method is to call the date and time commands of cmd:Copy codeThe Code is as follows: '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

A more technical method is to use the SetDateTime method of the WMI Win32_OperatingSystem class:Copy codeThe Code is as follows: 'author: Demon
'Website: http://demon.tw
'Date: 2011/4/27
DtmNewDateTime = "20380119031408.000000 + 480" 'utc time
StrComputer = "."
Set ob1_miservice = GetObject ("winmgmts: {(Systemtime) }\\" & strComputer & "\ root \ cimv2 ")
Set colOSes = ob1_miservice. ExecQuery ("Select * From Win32_OperatingSystem ")
For Each objOS In colOSes
ObjOS. SetDateTime dtmNewDateTime
Next

Windows 7 requires administrator privileges to enable UAC to modify the time.

Reference link:Hey, Scripting Guy! How Can I Set the Date and Time on a Computer?

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.