VBS boot automatically start sync system time

Source: Internet
Author: User
Tags set time

System time is always automatically changed to January 2003 days, and so on, the following methods can be used to solve, one, antivirus, two, (this method is more practical) available VBS synchronization system time, three, power-on hold down the Del to enter the CMOS set time, if still not possible is the motherboard time battery is dead, need to This is the VBS code, copy the code into a text document, and then the extension from TXT to VBS, you can solve.

=========================== (Copy the following code) ======================================

Set Fso=createobject ("Scripting.FileSystemObject")
Set Ws=createobject ("Wscript.Shell")
Set F=fso.getfile (Wscript.scriptfullname)
Ws.regwrite "Hkcusoftwaremicrosoftwindowscurrentversionrun" &f.name,f.path
' Created by escortmnm the from VBS team these codes are automatically started with the following code for automatic sync time

Strcomputer= "."
Set objswbemdatetime=createobject ("Wbemscripting.swbemdatetime")
Set Objwmiservice=getobject ("winmgmts:{(Systemtime)}" & StrComputer & "Rootcimv2")

Oldtime = Now ()

' Set a new date and time (available 10:38:00 PM format)
"2009-8-5 08:35:49"
Strnewdatetime=getservertime ()

Objswbemdatetime.setvardate Strnewdatetime,true
Dtmnewdatetime=objswbemdatetime.value

Set coloses=objwmiservice.execquery ("Select * from Win32_OperatingSystem")
For each objos in coloses
Objos.setdatetime Dtmnewdatetime
Next
NewTime = Now ()

WScript.Echo Oldtime & ">>>" & NewTime
Function getservertime ()
  URL = "Http://www.ti Me.ac.cn/stime.asp "
  InnerHTML = Bytestostr (Gethttppage (URL)," GB2312 ")
  Dim regEx, MH, MHS &NB sp;      ' establishes variable
   
  Set regEx = New regexp    ' establishes positive The expression
  regex.ignorecase = False ' Sets whether the character case is case-sensitive
  Regex.global = true       ;   ' Set global availability
   
  p1 = "<script language=[ss]+?document.write ([0-9]{4}) [ Ss]+? ([0-9]{1,2}) [ss]+? ([0-9]{1,2}) [ss]+? '] [Ss]+?var hrs = ([0-9]{2}) [Ss]+?var min = ([0-9]{2}] [Ss]+?var sec = ([0-9]{2})]
  Regex.pattern = P1
  Set MHS = Regex.execute (InnerHTML)     ' Execute search
  GetServerTime = Now ()
  If MHS. Count>0 Then
    net_year = CStr (MHS. Item (0). Submatches (0))
    net_month =CSTR (MHS. Item (0). Submatches (1))
    net_date = CStr (MHS. Item (0). Submatches (2))
    net_hour = CStr (MHS. Item (0). Submatches (3))
    Net_minute = CStr (MHS. Item (0). Submatches (4))
    Net_second = CStr (MHS. Item (0). Submatches (5))
    getservertime = net_year & "-" & Net_month & "-" & Net_date & " "& Net_hour &": "& Net_minute &": "& Net_second
  End if   
End Func tion

Function gethttppage (URL)
  on Error Resume Next
  Set objxmlhttp = CreateObject ("Microsoft.XMLHTTP ")
  Objxmlhttp.open" Get ", Url,false
  objxmlhttp.send ()
  If objxmlhttp.readystate <> 4 Then
    Exit Function
  End If
  gethttppage = objxmlhttp.responsebody
&N Bsp If err.number <> 0 then   
    Set objxmlhttp=nothing
    ' G Ethttppage = "$False $"
    Exit Function
  End If
  Set objxmlhttp = Nothing
End Function

Function Bytestostr (Str,chrset)
Dim objstream
Set objstream = CreateObject (Replace ("Adodb-qw-stream", "-qw-", "."))
Objstream.mode = 3
objStream.Type = 1
objStream.Open
Objstream.write STR
objstream.position = 0
objStream.Type = 2
Objstream.charset = Chrset
Bytestostr = Objstream.readtext
objStream.Close ()
Set objstream = Nothing
End Function

====================================== (dotted line do not copy) =======================================

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.