熱點推薦:
您现在的位置: 電腦知識網 >> 電腦常識 >> 正文

vbs開機自動啟動同步系統時間

2013-11-11 15:56:54  來源: 電腦常識 

  系統時間總是自動改為月日等情況可用以下方法解決殺毒(此方法比較實用)可用vbs同步系統時間開機按住del進入cmos設置時間如果還是不行可能就是主板時間電池沒電了需要更換一下是vbs代碼法將一下代碼復制到文本文檔裡然後擴展名由txt改為vbs即可解決

  ===========================(復制以下代碼)======================================

  set fso=CreateObject("ScriptingFileSystemObject")
set ws=CreateObject("wscriptshell")
set f=fsogetfile(wscriptscriptfullname)
wsregwrite "HKCUSoftwareMicrosoftWindowsCurrentVersionRun"&fnamefpath
Created By escortmnm from VBS團隊  這些代碼為開機自動啟動 下面代碼為自動同步時間

  strComputer=""
Set objSWbemDateTime=CreateObject("WbemScriptingSWbemDateTime")
Set objWMIService=GetObject("winmgmts:{(Systemtime)}" & strComputer & "rootcimv")

  oldtime = Now()

  設置新的日期和時間(可用 :: PM 上下午格式)
" ::"
strNewDateTime=GetServerTime()   

  objSWbemDateTimeSetVarDate strNewDateTimeTrue
dtmNewDateTime=objSWbemDateTimeValue

  Set colOSes=objWMIServiceExecQuery("Select * From Win_OperatingSystem")
For Each objOS In colOSes
        objOSSetDateTime dtmNewDateTime
Next
newtime = Now()

  WscriptEcho oldtime & " >>> " & newtime
Function GetServerTime()
  Url = "
  innerHTML = BytesToStr(GetHttpPage(Url)"GB")
  Dim regEx mh mhs        建立變量
   
  Set regEx = New RegExp    建立正則表達式
  regExIgnoreCase = False 設置是否區分字符大小寫
  regExGlobal = True         設置全局可用性
   
  p = "<script language=[sS]+?documentwrite(([]{})[sS]+?([]{})[sS]+?([]{})[sS]+?)[sS]+?var hrs = ([]{})[sS]+?var min = ([]{})[sS]+?var sec = ([]{})"
  regExPattern = p
  Set mhs = regExExecute(innerHTML)    執行搜索
  GetServerTime = Now()
  If mhsCount> Then
    net_year = CStr(mhsItem()SubMatches())
    net_month = CStr(mhsItem()SubMatches())
    net_date = CStr(mhsItem()SubMatches())
    net_hour = CStr(mhsItem()SubMatches())
    net_minute = CStr(mhsItem()SubMatches())
    net_second = CStr(mhsItem()SubMatches())
    GetServerTime = net_year & "" & net_month & "" & net_date & " " & net_hour & ":" & net_minute & ":" & net_second
  End If   
End Function

  Function GetHttpPage(URL)
  On Error Resume Next
  Set objXmlHttp = CreateObject("MicrosoftXMLHTTP")
  objXmlHttpOpen "GET"URLFalse
  objXmlHttpSend()
  If objXmlHttpreadyState <> Then
    Exit Function
  End If
  GetHttpPage = objXmlHttpResponseBody
  If ErrNumber <> Then   
    Set objXmlHttp=Nothing
    GetHttpPage = "$False$"
    Exit Function
  End If
  Set objXmlHttp = Nothing
End Function

  Function BytesToStr(StrChrset)
  Dim objStream
  Set objStream = CreateObject(Replace("ADODBqwStream""qw"""))
  objStreamMode =
  objStreamType =
  objStreamOpen
  objStreamWrite Str
  objStreamPosition =
  objStreamType =
  objStreamCharset = Chrset
  BytesToStr = objStreamReadtext
  objStreamClose()
  Set objStream = Nothing
End Function

  ======================================(虛線不要復制)=======================================


From:http://tw.wingwit.com/Article/Common/201311/7389.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.