컴퓨터/오토핫키

컴퓨터 시간을 웹사이트 시간으로 변경하는 프로그램

큐브빌드 2021. 3. 18. 14:40
반응형

cmd를 통해서 시간 변경하는 법은 벌써 한번 다루었는데요...

 

컴퓨터 시간 변경하기 (tistory.com)

 

컴퓨터 시간 변경하기

요즘 윈도를 사용하다 보니 컴퓨터 시간을 강제로 변경하기가 쉽지 않네요 물론 컴퓨터 배터리가 다 되어서 시간이 초기화된 이후 윈도에 접속하여 인터넷에서 시간을 맞춰주면 기분이 좋긴 하

downupup.tistory.com

하지만 이번에는 컴퓨터 시간을 웹사이트 시간에 맞춰서 변경되는 프로그램을 한번 만들어봤습니다.

 

아래 사이트를 참고하여 있는지 식 없는지 식을 동원하여 만들었습니다.

 

blog.naver.com/jyaqz/222261122230

 

컴퓨터 시간 서버(웹주소) 시간으로 변경 동기화 하기(오토핫키)

https://blog.naver.com/jyaqz/222250724080위 블로그에서 작성했듯​이제 컴퓨터 시간을 웹주소 서버 시간...

blog.naver.com

 

위 사이트와 차이점은 CMD로 수정하지 않고

 

kernel32.dll의 setsystemtime 함수를 사용하여 변경하는 방법입니다.

 

아마 cmd로 실행하는 것보다 시간의 오차가 적을 거라 생각합니다. (저의 뇌 피셜입니다. 신뢰하진 마세요^^;)

 

반드시 관리자 모드로 실행해야 합니다.

 

오토 핫키로 컴파일한 거라 바이러스라고 이야기할 수 있지만 바이러스는 없습니다.

 

timechange.exe
1.05MB

코드는 아래 첨부하였습니다.

 

참고했던 코드들이 많습니다.

 

날짜 파싱 하는 부분에서

 

Date parser - convert any date format to YYYYMMDDHH24 MISS - Scripts and Functions - AutoHotkey Community

 

Date parser - convert any date format to YYYYMMDDHH24MISS - Scripts and Functions

Page 1 of 7 - Date parser - convert any date format to YYYYMMDDHH24MISS - posted in Scripts and Functions: This function converts almost any date format to a YYYYMMDDHH24MISS value.Inspired by philz InvFormattime.e.g. time := DateParse(2:35 PM, 27 November

autohotkey.com

 

SetSystemTime의 코드는

SetSystemTime() : Updates system time with time returned from a Time Server - AutoHotkey Community

 

SetSystemTime() : Updates system time with time returned from a Time Server - AutoHotkey Community

 

www.autohotkey.com

 

여기를 참조하였습니다.

#NoEnv
#SingleInstance, Force

inputbox , ad , 주소를 입력해주세요
adcheck := instr(ad , "http://")
adcheck := % adcheck + instr(ad , "https://")
if adcheck <> 1
{
msgbox "주소를 바르게 넣어주세요"
exit app
}

wh := ComObjCreate("WinHTTP.WinHTTPRequest.5.1") 
wh.Open("GET", ad)
wh.send
wh.WaitForResponse
d := wh.getallresponseheaders
Clipboard := % d
loop , parse , d , `n
{
  num := instr(A_LoopField , "Date:")
   if num > 0
   {
     
    DateValue := substr(A_LoopField , 11 , 12)
    StringReplace , DateValue , DateValue , %A_Space% , ,,all
    TimeValue := substr(A_LoopField , 24 , 8)
    StringReplace , TimeValue , TimeValue , :, ,,all
    DateValue := DateParse(DateValue)
    Time := % DateValue TimeValue
   }
}


YYYYMMDDHHMISS := Time ; reassigning variable so I don`t have to edit the doc example

VarSetCapacity(SystemTime, 16, 0)  ; This struct consists of 8 UShorts (i.e. 8*2=16).

Int := SubStr(YYYYMMDDHHMISS, 1, 4)  ; YYYY (year)
NumPut(Int, SystemTime, 0, "UShort")
Int := SubStr(YYYYMMDDHHMISS, 5, 2)  ; MM (month of year, 1-12)
NumPut(Int, SystemTime, 2, "UShort")
Int := SubStr(YYYYMMDDHHMISS, 7, 2)  ; DD (day of month)
NumPut(Int, SystemTime, 6, "UShort")
Int := SubStr(YYYYMMDDHHMISS, 9, 2)  ; HH (hour in 24-hour time)
NumPut(Int, SystemTime, 8, "UShort")
Int := SubStr(YYYYMMDDHHMISS, 11, 2) ; MI (minute)
NumPut(Int, SystemTime, 10, "UShort")
Int := SubStr(YYYYMMDDHHMISS, 13, 2) ; SS (second)
NumPut(Int, SystemTime, 12, "UShort")

DllCall("SetSystemTime", "Ptr", &SystemTime)  

msgbox "시간이 변경되었습니다."

DateParse(ByRef str) {
	static e2 = "i)(?:(\d{1,2}+)[\s\.\-\/,]+)?(\d{1,2}|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*)[\s\.\-\/,]+(\d{2,4})"
	str := RegExReplace(str, "((?:" . SubStr(e2, 42, 47) . ")\w*)(\s*)(\d{1,2})\b", "$3$2$1", "", 1)
	If RegExMatch(str, "i)^\s*(?:(\d{4})([\s\-:\/])(\d{1,2})\2(\d{1,2}))?"
		. "(?:\s*[T\s](\d{1,2})([\s\-:\/])(\d{1,2})(?:\6(\d{1,2})\s*(?:(Z)|(\+|\-)?"
		. "(\d{1,2})\6(\d{1,2})(?:\6(\d{1,2}))?)?)?)?\s*$", i)
		d3 := i1, d2 := i3, d1 := i4, t1 := i5, t2 := i7, t3 := i8
	Else If !RegExMatch(str, "^\W*(\d{1,2}+)(\d{2})\W*$", t)
		RegExMatch(str, "i)(\d{1,2})\s*:\s*(\d{1,2})(?:\s*(\d{1,2}))?(?:\s*([ap]m))?", t)
			, RegExMatch(str, e2, d)
	f = %A_FormatFloat%
	SetFormat, Float, 02.0
	d := (d3 ? (StrLen(d3) = 2 ? 20 : "") . d3 : A_YYYY)
		. ((d2 := d2 + 0 ? d2 : (InStr(e2, SubStr(d2, 1, 3)) - 40) // 4 + 1.0) > 0
			? d2 + 0.0 : A_MM) . ((d1 += 0.0) ? d1 : A_DD) . t1
			+ (t1 = 12 ? t4 = "am" ? -12.0 : 0.0 : t4 = "am" ? 0.0 : 12.0) . t2 + 0.0 . t3 + 0.0
	SetFormat, Float, %f%
	Return, d
}

 

궁금한 게 있으시면 댓글로 언제든 물어봐주시면 알려드리겠습니다.

반응형