欢迎您访问我爱IT技术网,今天小编为你分享的电脑教程是日常使用电脑方面的电脑常识:vbs开机自动启动同步系统时间,学会并运用这些电脑常识,让你快速玩转电脑及互联网方面的知识,下面是详细的分享!
vbs开机自动启动同步系统时间
系统时间总是自动改为2003年1月日等情况,可用以下方法解决,一,杀毒,二,(此方法比较实用)可用vbs同步系统时间,三,开机按住del进入cmos设置时间,如果还是不行可能就是主板时间电池没电了,需要更换。一下是vbs代码法,将一下代码复制到文本文档里,然后扩展名由txt改为vbs,即可解决。
===========================(复制以下代码)======================================
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 from VBS团队 这些代码为开机自动启动 下面代码为自动同步时间
strComputer="."
Set objSWbemDateTime=CreateObject("WbemScripting.SWbemDateTime")
Set objWMIService=GetObject("winmgmts:{(Systemtime)}" & strComputer & "rootcimv2")
oldtime=Now()
'设置新的日期和时间(可用 10:38:00 PM 上下午格式)
'"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.time.ac.cn/stime.asp"
innerHTML=BytesToStr(GetHttpPage(Url),"GB2312")
Dim regEx, mh, mhs '建立变量
Set regEx=New RegExp '建立正则表达式
regEx.IgnoreCase=False '设置是否区分字符大小写
regEx.Global=True '设置全局可用性
p1="
regEx.Pattern=p1
Set mhs=regEx.Execute(innerHTML) '执行搜索
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 Function
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
If Err.Number <> 0 Then
Set objXmlHttp=Nothing
'GetHttpPage="$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
======================================(虚线不要复制)=======================================
以上就是关于vbs开机自动启动同步系统时间的电脑常识分享,更多电脑教程请移步到>>电脑教程频道。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
