Declare Sub GetSystemTimeAsFileTime Lib "kernel32.dll" (lpSystemTimeAsFileTime As FILETIME)
GetSystemTimeAsFileTime retrieves the current system date and time and places it into a FILETIME structure. The system time is always reported in UTC time (Coordinated Universal Time, a.k.a. Greenwich Mean Time (GMT)).
GetSystemTimeAsFileTime does not return a value.
None.
' This code is licensed according to the terms and conditions listed here.
' Set the modification time of C:\MyApp\test.txt to
' the current system date and time. Leave the other times as they
' were before calling the function.
Dim hFile As Long ' handle to the opened file
Dim ctime As FILETIME ' the time of creation
Dim atime As FILETIME ' the time of last access
Dim mtime As FILETIME ' the time of last modification
Dim retval As Long ' return value
' First, open the file C:\MyApp\test.txt for both read-level and
' write-level access, since we need to do both.
hFile = CreateFile("C:\MyApp\test.txt", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
If hFile = -1 Then
Debug.Print "Could not open the file successfully -- aborting."
End ' terminate the program
End If
' Next, get the creation, last-access, and last-modification times.
retval = GetFileTime(hFile, ctime, atime, mtime)
' Get the system time (already in UTC) as a FILETIME structure.
GetSystemTimeAsFileTime mtime
' Set the retrieved creation and access times and the new modification
' time as the file's times.
retval = SetFileTime(hFile, ctime, atime, mtime)
' Close the file to free up resources.
retval = CloseHandle(hFile)
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: October 2, 1999
This page is copyright © 1999 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getsystemtimeasfiletime.html