Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Type TIME_OF_DAY_INFO
- tod_elapsedt As Long
- tod_msecs As Long
- tod_hours As Long
- tod_mins As Long
- tod_secs As Long
- tod_hunds As Long
- tod_timezone As Long
- tod_tinterval As Long
- tod_day As Long
- tod_month As Long
- tod_year As Long
- tod_weekday As Long
- End Type
- Declare Function NetRemoteTOD Lib "NetApi32" (ByRef UncServerName As Any, ByRef BufferPtr As Any) As Long
- '====================================================================
- Public Sub Main()
- asRegisterAppPath
- InitCommonControls
- If Not asIsInIDE Then asSetWindowResIconAll asGetThunderMainHandle(), IDI_APPICON
- Dim TOD As TIME_OF_DAY_INFO
- Dim lpTOD As Long
- Dim MachineName() As Byte
- Dim RC As Long
- Dim ST As SYSTEMTIME
- Dim TXT As BStr
- Dim Cmd As BStr
- Cmd = asTrimEx2(Command, True, True, True, True, True)
- Cmd = UCase(Cmd)
- If Cmd = "" Then Cmd = "."
- #If SIMULATE_ERROR Then
- MachineName = StrConv(Cmd & NUL, vbFromUnicode)
- #Else
- MachineName = Cmd & NUL
- #End If
- RC = NetRemoteTOD(MachineName(0), lpTOD)
- If RC <> 0 Then
- asLogError "NetRemoteTOD() failed." & CRLF & _
- "Error " & asGetErrorNumber(RC) & ":" & CRLF & _
- asGetAPIErrorMessage(RC)
- Else
- ' On return a pointer to the return information structure
- ' TIME_OF_DAY_INFO is returned in the address pointed to
- ' by BufferPtr.
- If lpTOD = 0 Then
- asLogError "NetRemoteTOD() returns NULL pointer."
- Else
- CopyMemory TOD.tod_elapsedt, ByVal lpTOD, Len(TOD)
- GetSystemTime ST
- TXT = "Local date & time: " & ST.wDay & "." & _
- Format(ST.wMonth, "00") & "." & _
- Format(ST.wYear, "0000") & " " & _
- ST.wHour & ":" & _
- Format(ST.wMinute, "00") & ":" & _
- Format(ST.wSecond, "00") & "." & _
- ST.wMilliseconds & CRLF & _
- "Remote date & time: " & TOD.tod_day & "." & _
- Format(TOD.tod_month, "00") & "." & _
- Format(TOD.tod_year, "0000") & " " & _
- TOD.tod_hours & ":" & _
- Format(TOD.tod_mins, "00") & ":" & _
- Format(TOD.tod_secs, "00") & "." & _
- TOD.tod_hunds & CRLF & _
- "Remote system name: " & Cmd & CRLFCRLF & _
- "Please note both times are in UTC format."
- Debug.Print TXT
- If Not asSetPrivilegeForProcess(SE_SYSTEMTIME_NAME, True) Then
- asLogWarning "Failed to set SE_SYSTEMTIME_NAME privilege."
- End If
- ST.wDay = TOD.tod_day
- ST.wDayOfWeek = 0
- ST.wHour = TOD.tod_hours
- ST.wMilliseconds = TOD.tod_hunds
- ST.wMinute = TOD.tod_mins
- ST.wMonth = TOD.tod_month
- ST.wSecond = TOD.tod_secs
- ST.wYear = TOD.tod_year
- If SetSystemTime(ST) = C_FALSE Then
- asLogError "SetSystemTime() failed." & CRLFCRLF & TXT
- Else
- asLogInfo "System time was updated successfully." & CRLFCRLF & TXT
- End If
- End If
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement