|
本帖最后由 风中柳 于 2011-5-9 14:38 编辑
最近电脑时间总是不准,换了电池不也行!我想能不能用au3编一个校对时间的程序,在双击程序之后将这个程序复制到C:\windows下,并添加到注册表中,使它每次开机时随机启动并自动对时!我在论坛里找到了一个源码!但是总无法实现将程序复制到C:\windows下和添加到注册表的run中?请大家帮帮忙!
#NoTrayIcon
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#Region ;**** 参数创建于 AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Region
#EndRegion
#Include <Misc.au3>
#include <Date.au3>
$ntpServer = "time-nw.nist.gov" ;改为ini配置
local $var1,$var2
;Global Const $tagSYSTEMTIME = "short Year;short Month;short Dow;short Day;short Hour;short Minute;short Second;short MSeconds"
;Global Const $tagTIME_ZONE_INFORMATION = "dword Bias;byte StdName[64];ushort StdDate[8];dword StdBias;byte DayName[64];ushort DayDate[8];dword DayBias"
dim $TimeZone=8*60*60
UDPStartup()
Dim $socket = UDPOpen(TCPNameToIP($ntpServer), 123)
If @error <> 0 Then
MsgBox(0,"","连接服务器失败!")
Exit
EndIf
;$status = UDPSend($socket, MakePacket("1b0e010000000000000000004c4f434ccb1eea7b866665cb00000000000000000000000000000000cb1eea7b866665cb"))
$status = UDPSend($socket, MakePacket("1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
If $status = 0 Then
MsgBox(4096, "错误", "连接服务器失败,请查看网络连接!")
EndIf
$data=""
$i=0
While $data=""
$i+=1
$data = UDPRecv($socket, 100)
If $i = 5 Then
MsgBox(4096, "错误", "连接服务器失败,请更换服务器地址!")
Exit
EndIf
sleep(100)
WEnd
UDPCloseSocket($socket)
UDPShutdown()
$unsignedHexValue=StringMid($data,83,8); Extract time from packet. Disregards the fractional second.
$value=UnsignedHexToDec($unsignedHexValue)
$value=$value+$TimeZone
$UTC=_DateAdd("s",$value,"1900/01/01 00:00:00")
$var1=StringSplit(StringLeft($UTC,10),'/')
$var2=StringSplit(StringRight($UTC,8),':')
_SetTime($var2[1],$var2[2],$var2[3])
_SetDate($var1[3],$var1[2],$var1[1])
MsgBox(0,"提示","NTP服务器时间同步成功,当前系统时间为: "&$UTC)
Func MakePacket($d)
Local $p=""
While $d
$p&=Chr(Dec(StringLeft($d,2)))
$d=StringTrimLeft($d,2)
WEnd
Return $p
EndFunc
Func UnsignedHexToDec($n)
$ones=StringRight($n,1)
$n=StringTrimRight($n,1)
Return dec($n)*16+dec($ones)
EndFunc |
|