Jump to content

Question about _Date_Time_GetSystemTimeAsFileTime


Recommended Posts

Is the function supposed to return the current date in the UTC format?, that's how I understand it. I am trying to convert the current time and date to the UTC format but just get an empty message box.

#include <date.au3>

MsgBox(0,'Time', _Date_Time_GetSystemTimeAsFileTime())
Edited by benners
Link to comment
Share on other sites

Is the function supposed to return the current date in the UTC format?, that's how I understand it. I am trying to convert the current time and date to the UTC format but just get an empty message box.

#include <date.au3>

MsgBox(0,'Time', _Date_Time_GetSystemTimeAsFileTime())
That function returns a DLL structure, not a plain string. To convert:
#include <date.au3>
$tCur = _Date_Time_GetSystemTime()
MsgBox(0,'Time', _Date_Time_SystemTimeToDateTimeStr($tCur))

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

That function returns a DLL structure, not a plain string. To convert:

#include <date.au3>
$tCur = _Date_Time_GetSystemTime()
MsgBox(0,'Time', _Date_Time_SystemTimeToDateTimeStr($tCur))

:P

Hi PsaltyDS,

I don't need the string I need the integer similar to when dates are converted to Epoch. I am trying to update a files time stamp and the format has to be VT_Filetime. With VBS the Now function sends the correct format but using AutoIt _Now() the update fails.

I did something a while ago for Paint Shop Pro

$iDateCalc = _DateDiff('s', "1970/01/01 00:00:00", _NowCalc())

the file accepts the update but the time is wrong it ended up bieng 30/07/1607 02:03:12

Link to comment
Share on other sites

Hi PsaltyDS,

I don't need the string I need the integer similar to when dates are converted to Epoch. I am trying to update a files time stamp and the format has to be VT_Filetime. With VBS the Now function sends the correct format but using AutoIt _Now() the update fails.

I did something a while ago for Paint Shop Pro

$iDateCalc = _DateDiff('s', "1970/01/01 00:00:00", _NowCalc())

the file accepts the update but the time is wrong it ended up bieng 30/07/1607 02:03:12

File times are not seconds since Epoch, they are 64bit integer 0.1usecs ticks since 01/01/1601. See $tagFILETIME (also MSDN) in the help file, which is the structure you got back from _Date_Time_GetSystemTimeAsFileTime() in the first place:
#include <Date.au3>
; $tagFILETIME = "dword Lo;dword Hi"
$structFILETIME = _Date_Time_GetSystemTimeAsFileTime()

ConsoleWrite("Debug: Lo = " & DllStructGetData($structFILETIME, "Lo") & @LF)
ConsoleWrite("Debug: Hi = " & DllStructGetData($structFILETIME, "Hi") & @LF)

$sFILETIME = "0x" & Hex(DllStructGetData($structFILETIME, "Hi"), 8) & Hex(DllStructGetData($structFILETIME, "Lo"), 8)
ConsoleWrite("Debug: 0.1 microsecond ticks since January 01, 1601 = " & $sFILETIME & @LF)

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

File times are not seconds since Epoch, they are 64bit integer 0.1usecs ticks since 01/01/1601. See $tagFILETIME (also MSDN) in the help file, which is the structure you got back from _Date_Time_GetSystemTimeAsFileTime() in the first place:

#include <Date.au3>
; $tagFILETIME = "dword Lo;dword Hi"
$structFILETIME = _Date_Time_GetSystemTimeAsFileTime()

ConsoleWrite("Debug: Lo = " & DllStructGetData($structFILETIME, "Lo") & @LF)
ConsoleWrite("Debug: Hi = " & DllStructGetData($structFILETIME, "Hi") & @LF)

$sFILETIME = "0x" & Hex(DllStructGetData($structFILETIME, "Hi"), 8) & Hex(DllStructGetData($structFILETIME, "Lo"), 8)
ConsoleWrite("Debug: 0.1 microsecond ticks since January 01, 1601 = " & $sFILETIME & @LF)

:P

That's what I wanted in the first place :-) but the value returned from _Date_Time_GetSystemTimeAsFileTime is blank, how do I display this info?.

I tried your code above and it obviously works but the returned value is not accepted to update the file. Both DllStructGetData($structFILETIME, "Lo") and DllStructGetData($structFILETIME, "Hi") return values that are accepted but the new file time is still wrong the year is 1607, do I have to do some conversion to return a 64 integer that equates to todays current time and date?

Thanks for your help

Link to comment
Share on other sites

That's what I wanted in the first place :-) but the value returned from _Date_Time_GetSystemTimeAsFileTime is blank, how do I display this info?.

I tried your code above and it obviously works but the returned value is not accepted to update the file. Both DllStructGetData($structFILETIME, "Lo") and DllStructGetData($structFILETIME, "Hi") return values that are accepted but the new file time is still wrong the year is 1607, do I have to do some conversion to return a 64 integer that equates to todays current time and date?

Thanks for your help

You haven't said yet what function you are using to set the file time, have you? Anyway, it probably wants the $structFILETIME as an input (or a pointer to it), not just parts of it. We don't know until we see how you are using it...

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You haven't said yet what function you are using to set the file time, have you? Anyway, it probably wants the $structFILETIME as an input (or a pointer to it), not just parts of it. We don't know until we see how you are using it...

:P

The file is an MSI, I am creating a Windows.Installer object then opening the database and updating the MSI files time stamp. The accepted format for the property I am updating is VT_FILETIME and if using VB Script the Now Function returns a correct format to update the file, what I am trying to to o is return the VT_FILETIME format which is a 64bit integer as you said previously.

The part of the code that updates the file time is $nValue, this is supplied to the function as a parameter

$SumInfo = $obj.SummaryInformation($MSP2Read, 1); Read the summary information
$SumInfo.Property($iProperty) = $nValue
$SumInfo.Persist

So I am trying to supply an integer that does not fail and sets the current date and time.

Thanks

Edited by benners
Link to comment
Share on other sites

The file is an MSI, I am creating a Windows.Installer object then opening the database and updating the MSI files time stamp. The accepted format for the property I am updating is VT_FILETIME and if using VB Script the Now Function returns a correct format to update the file, what I am trying to to o is return the VT_FILETIME format which is a 64bit integer as you said previously.

The part of the code that updates the file time is $nValue, this is supplied to the function as a parameter

$SumInfo = $obj.SummaryInformation($MSP2Read, 1); Read the summary information
$SumInfo.Property($iProperty) = $nValue
$SumInfo.Persist

So I am trying to supply an integer that does not fail and sets the current date and time.

Thanks

It still looks to me like it is a DLL struct, not a straight integer value that you should pass:
#include <date.au3>

; ...

$tValue = _Date_Time_GetSystemTime()
$SumInfo.Property($iProperty) = $tValue
$SumInfo.Persist

Although I don't see anything that says that, it could want the pointer to the struct, which would be:

#include <date.au3>

; ...

$tValue = _Date_Time_GetSystemTime()
$SumInfo.Property($iProperty) = DllStructGetPtr($tValue)
$SumInfo.Persist

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

It still looks to me like it is a DLL struct, not a straight integer value that you should pass:

#include <date.au3>

; ...

$tValue = _Date_Time_GetSystemTime()
$SumInfo.Property($iProperty) = $tValue
$SumInfo.Persist

Although I don't see anything that says that, it could want the pointer to the struct, which would be:

#include <date.au3>

; ...

$tValue = _Date_Time_GetSystemTime()
$SumInfo.Property($iProperty) = DllStructGetPtr($tValue)
$SumInfo.Persist

:P

I tried the code you posted but neither value was not accepted. I have been lookin through the help file and normally steer clear of DLL things but would it work if I used DllStructCreate, something like he code below, I don't know if the format is correct and haven't tried this variation.

$a = DllStructCreate('uint64')
DllStructSetData($a,"", _Date_Time_GetSystemTimeAsFileTime())

Thanks

Edited by benners
Link to comment
Share on other sites

I tried the code you posted but neither value was not accepted. I have been lookin through the help file and normally steer clear of DLL things but would it work if I used DllStructCreate, something like he code below, I don't know if the format is correct and haven't tried this variation.

$a = DllStructCreate('uint64')
DllStructSetData($a,"", _Date_Time_GetSystemTimeAsFileTime())

Thanks

I just don't know, maybe one of the smart people will chime in. The VT_FILETIME struct is clearly divided into 32bit "Hi" and "Lo" elements in the MSDN documentation (see link in post #4), and in AutoIt's $tagFILETIME, so it looked to me like that should have worked.

What OS and AutoIt versions are you using, and is the filesystem NTFS (not that I know it makes any difference)?

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I just don't know, maybe one of the smart people will chime in. The VT_FILETIME struct is clearly divided into 32bit "Hi" and "Lo" elements in the MSDN documentation (see link in post #4), and in AutoIt's $tagFILETIME, so it looked to me like that should have worked.

What OS and AutoIt versions are you using, and is the filesystem NTFS (not that I know it makes any difference)?

:P

I am using Win XP Pro, AutoIt v3.2.10.0 but compiling with the latest beta on NTFS. Thanks for your help I an going to keep playing with different functions and sending integers to see if I can blindly stumble on a solution :-) Edited by benners
Link to comment
Share on other sites

#include <GuiConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>

Global $iMemo

_Main()

Func _Main()
    Local $hGUI, $tTime

    ; Create GUI
    $hGUI = GUICreate("Time", 400, 300)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    $tTime = _Date_Time_GetSystemTimeAsFileTime()
    MemoWrite("Lo: " & DllStructGetData($tTime, "Lo"))
    MemoWrite("High: " & DllStructGetData($tTime, "Hi"))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    
EndFunc   ;==>_Main

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

#include <GuiConstantsEx.au3>
#include <Date.au3>
#include <WindowsConstants.au3>

Global $iMemo

_Main()

Func _Main()
    Local $hGUI, $tTime

; Create GUI
    $hGUI = GUICreate("Time", 400, 300)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    $tTime = _Date_Time_GetSystemTimeAsFileTime()
    MemoWrite("Lo: " & DllStructGetData($tTime, "Lo"))
    MemoWrite("High: " & DllStructGetData($tTime, "Hi"))

; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    
EndFunc  ;==>_Main

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc  ;==>MemoWrite
Gary,

Thanks for the demo, but it shows the wrong end of the process for the OP. He was trying to figure out why passing the $tTime struct as an input parameter wasn't working. (See OP's post #7.)

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

@Benners,

What you are after is reading the DateAndTime from the MSI records.

This will get you going.

GUICtrlSetData($Listbox1, "Last Printed: " & WMIDateStringToDateTime_EURO($SumInfo.Property(11)) )
GUICtrlSetData($Listbox1, "Creation Date: " & WMIDateStringToDateTime_EURO($SumInfo.Property(12)) )
GUICtrlSetData($Listbox1, "Last Saved: " & WMIDateStringToDateTime_EURO($SumInfo.Property(13)) )

; Date and Time conversion
Func WMIDateStringToDateTime_EURO($dtmDate)
    Return(StringRegExpReplace($dtmDate, "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)","$1/$2/$3 $4:$5:$6"))
EndFunc

Look also in my signature for the MSI browser. Run it and click on summary information.

regards,

ptrex

Link to comment
Share on other sites

@Benners,

What you are after is reading the DateAndTime from the MSI records.

This will get you going.

GUICtrlSetData($Listbox1, "Last Printed: " & WMIDateStringToDateTime_EURO($SumInfo.Property(11)) )
GUICtrlSetData($Listbox1, "Creation Date: " & WMIDateStringToDateTime_EURO($SumInfo.Property(12)) )
GUICtrlSetData($Listbox1, "Last Saved: " & WMIDateStringToDateTime_EURO($SumInfo.Property(13)) )

; Date and Time conversion
Func WMIDateStringToDateTime_EURO($dtmDate)
    Return(StringRegExpReplace($dtmDate, "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)","$1/$2/$3 $4:$5:$6"))
EndFunc

Look also in my signature for the MSI browser. Run it and click on summary information.

regards,

ptrex

Link to comment
Share on other sites

@Benners,

What you are after is reading the DateAndTime from the MSI records.

This will get you going.

GUICtrlSetData($Listbox1, "Last Printed: " & WMIDateStringToDateTime_EURO($SumInfo.Property(11)) )
GUICtrlSetData($Listbox1, "Creation Date: " & WMIDateStringToDateTime_EURO($SumInfo.Property(12)) )
GUICtrlSetData($Listbox1, "Last Saved: " & WMIDateStringToDateTime_EURO($SumInfo.Property(13)) )

; Date and Time conversion
Func WMIDateStringToDateTime_EURO($dtmDate)
    Return(StringRegExpReplace($dtmDate, "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)","$1/$2/$3 $4:$5:$6"))
EndFunc

Look also in my signature for the MSI browser. Run it and click on summary information.

regards,

ptrex

Thanks all for the replies,

@ptrex

I originally tried something similar but just by sending @year & @mon etc but as PsaltyDS mentioned it needs to be an integer to update the date.

I have been trying to find out how the VB Script "Now" function works as in a vbs script that is how the time stamp is updated but couldn't find anything, the closest I came was an archived page that may or may not be relevant. I tried to emulate what it did with AutoIt but it didn't work either I am doing it wrong (most likely) or it would not work anyway.

I have decided to put this on the back burner as it is wasting my time at the moment but below is the script I have been trying to use. The commented code are previous attempts and the latest is the date calc one.

#include <Date.au3>

; When applied to MSI
; $t1                      = 16/07/1607 01:08:13
; $t2                      = 26/07/1607 06:25:39
; $tTime                    = Error
; $t1 * 65535 * 65535 + $t2 = 25/07/1607 11:20:19
; $tStamp                  = 11/08/1607 05:09:24
; $iDateCalc                = 15/07/1607 15:35:34 using 1ns as 1000000000
;                          = 25/07/1607 00:50:24 using 100-ns intervals as 10000000 ?
#cs
$structFILETIME  = _Date_Time_GetSystemTimeAsFileTime()
$t1 = "0x" & Hex(DllStructGetData($structFILETIME, "Hi"), 8)
$t2 = Hex(DllStructGetData($structFILETIME, "Lo"), 8)

$a = DllStructCreate('double')
DllStructSetData($a, 1, $t1)

$b = DllStructCreate('double')
DllStructSetData($b, 1, $t2)

$t3 = DllStructGetData($a, 1, 1)
$t4 = DllStructGetData($b, 1, 1)

$tStamp = $t3 * 65535 * 65535 + $t4
#ce
$iDateCalc = (_DateDiff( 's',"1601/01/01 00:00:00",_NowCalc()) * 10000000)

MSI_SummaryInfo('C:\BackUp\STD.MSI', 13, $iDateCalc, 1)

Func MSI_SummaryInfo($MSP2Read, $iProperty, $nValue = '', $iMode = 0); Get the summary info from an MSP ($MSP2Read = MSP file, $iProperty = Property string to get, $iMode = 0 Read info, 1 Update info).
    Local $Installer, $SumInfo

    $Installer = ObjCreate("WindowsInstaller.Installer"); Create a reference to the Windows Installer COM.

    If Not IsObj($Installer) Then; Problem creating the COM object.
    Else
        If $iMode = 0 Then; Onlt read the Summary Info.
            $SumInfo = $Installer.SummaryInformation($MSP2Read, 0); Read the summary information
            Return $SumInfo.Property($iProperty); Return  the property string.
        Else; Write new Summary Info.
            $SumInfo = $Installer.SummaryInformation($MSP2Read, 1); Read the summary information
            $SumInfo.Property($iProperty) = $nValue
            $SumInfo.Persist
        EndIf
    EndIf
EndFunc  ;==>MSI_SummaryInfo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...