You beat me
Anyway, the DllCall documentation could probably use another structure-passing example, so here's one that changes the clock via DllCall("SetSystemTime").
Only the very first line needs to be altered. All the rest just takes care of actually setting the specified time. Use caution when changing to a date in the future as it may cause scheduled tasks to run prematurely!
Code:
SetSystemTime("20051008142211") ; Pass it a timestamp (local not UTC).
SetSystemTime(YYYYMMDDHHMISS)
; Sets the system clock to the specified date and time.
; Caller must ensure that the incoming parameter is a valid date-time stamp
; (local time, not UTC). Returns non-zero on success and zero otherwise.
{
; Convert the parameter from local time to UTC for use with SetSystemTime().
UTC_Delta -= %A_NowUTC%, Seconds ; Seconds is more accurate due to rounding issue.
UTC_Delta := Round(-UTC_Delta/60) ; Round to nearest minute to ensure accuracy.
YYYYMMDDHHMISS += %UTC_Delta%, Minutes
VarSetCapacity(SystemTime, 16, 0) ; Struct consists of 8 UShorts (i.e. 8*2=16)
StringLeft, Int, YYYYMMDDHHMISS, 4 ; YYYY (year)
InsertInteger(Int, SystemTime, 0, 2)
StringMid, Int, YYYYMMDDHHMISS, 5, 2 ; MM (month of year, 1-12)
InsertInteger(Int, SystemTime, 2, 2)
StringMid, Int, YYYYMMDDHHMISS, 7, 2 ; DD (day of month)
InsertInteger(Int, SystemTime, 6, 2)
StringMid, Int, YYYYMMDDHHMISS, 9, 2 ; HH (hour in 24-hour time)
InsertInteger(Int, SystemTime, 8, 2)
StringMid, Int, YYYYMMDDHHMISS, 11, 2 ; MI (minute)
InsertInteger(Int, SystemTime, 10, 2)
StringMid, Int, YYYYMMDDHHMISS, 13, 2 ; SS (second)
InsertInteger(Int, SystemTime, 12, 2)
return DllCall("SetSystemTime", str, SystemTime)
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
mask := 0xFF ; This serves to isolate each byte, one by one.
Loop %pSize% ; Copy each byte in the integer into the structure as raw binary data.
{
DllCall("RtlFillMemory", UInt, &pDest + pOffset + A_Index - 1, UInt, 1
, UChar, (pInteger & mask) >> 8 * (A_Index - 1))
mask := mask << 8 ; Set it up for isolation of the next byte.
}
}