Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Search Results for "FILETIME" in [All]

Structures

.

        public FILETIME CreationTime;

.

        public FILETIME LastAccessTime;

.

        public FILETIME LastWriteTime;

.

  <FieldOffset(4)> Public ftCreationTime As Int64         ' FILETIME

.

  <FieldOffset(12)> Public ftLastAccessTime As Int64      ' FILETIME

.

  <FieldOffset(20)> Public ftLastWriteTime As Int64       ' FILETIME

.

    val mutable CreationTime:FILETIME

.

    val mutable LastAccessTime:FILETIME

.

    val mutable LastWriteTime:FILETIME

.

   public FILETIME NotBefore;

.

   public FILETIME NotAfter;

.

       public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;

.

       public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime;

.

       public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;

.

    Public ftCreationTime As System.Runtime.InteropServices.ComTypes.FILETIME

.

    Public ftLastAccessTime As System.Runtime.InteropServices.ComTypes.FILETIME

.

    Public ftLastWriteTime As System.Runtime.InteropServices.ComTypes.FILETIME

.
Summary
FILETIME
.

public struct FILETIME {

.

Public Structure FILETIME

.

[System.Runtime.InteropServices.FILETIME] (obsolete), or [System.Runtime.InteropServices.ComTypes.FILETIME] in the .NET Framework 2.0.

.

There is no reason not to use [System.Runtime.InteropServices.ComTypes.FILETIME], but there still is a need for conversion to [DateTime]:

.

    public static DateTime FiletimeToDateTime(FILETIME fileTime) {

.

        long hFT2 = (((long) fileTime.dwHighDateTime) << 32) | ((uint) fileTime.dwLowDateTime);

.

        return DateTime.FromFileTimeUtc(hFT2);

.

    public static FILETIME DateTimeToFiletime(DateTime time) {

.

        FILETIME ft;

.

        long hFT1 = time.ToFileTimeUtc();

.

Actually, this is NOT working. The only solution I've found so far is using the API Kernel32.dll function FileTimeToSystemTime, then transforming from that into a regular DateTime.

.

* Note that System.Runtime.InteropServices.FILETIME is now obsolete. Changed to use System.Runtime.InteropServices.ComTypes.FILETIME instead.

.

    Private Shared Function ConvertFileTimeToDateTime(input As FILETIME) As DateTime

.

    Return DateTime.FromFileTime(longTime)

.

    struct FILETIME {

.

            get { return DateTime.FromFileTime(this.timestamp); }

.

            set { this.timestamp = value.ToFileTime(); }

.

            get { return DateTime.FromFileTimeUtc(this.timestamp); }

.

            set { this.timestamp = value.ToFileTimeUtc(); }

.
Documentation
[FILETIME] on MSDN
.

    public System.Runtime.InteropServices.ComTypes.FILETIME DriverDate;

.

    public System.Runtime.InteropServices.ComTypes.FILETIME DriverDate;

.

    public FILETIME mtime;

.

    public FILETIME ctime;

.

    public FILETIME atime;

.

        public FILETIME ftCreationTime;

.

        public FILETIME ftLastAccessTime;

.

        public FILETIME ftLastWriteTime;

.

   Public ftCreationTime As FILETIME

.

   Public ftLastAccessTime As FILETIME

.

   Public ftLastWriteTime As FILETIME

.

    public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;

.

    public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime;

.

    public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;

.

    Public ftCreationTime As System.Runtime.InteropServices.ComTypes.FILETIME

.

    Public ftLastAccessTime As System.Runtime.InteropServices.ComTypes.FILETIME

.

    Public ftLastWriteTime As System.Runtime.InteropServices.ComTypes.FILETIME

.

FILETIME is in System.Runtime.InteropServices. The ComTypes namespace is introduced with .net 2.0

.

I actually discovered a problem using the System.Runtime.InteropServices.ComTypes.FILETIME structure for the ftLastAccessTime and ftLastWriteTime members. The FILETIME is defined by the .NET framework as a high and low component, both of type int. This worked fine in almost all cases.

.

The problem I saw was when the file had no FILETIME information (0) as the file was created on a MAC inside of a ZIP file. When trying to get back to a DateTime using the DateTime.FromFileTimeUtc the DateTime created was 12/31/1979 23:52:50 (seven minutes and ten seconds before 1/1/1980) instead of 1/1/1980 00:00:00. I am in Arizona which always has a seven HOUR offset from GMT so I don't know if that played into the calculation or not (seven minutes vs. seven hours).

.

    public struct WIN32_FIND_FILETIME

.

    /// Specifies the low 32 bits of the FILETIME.

.

    /// Specifies the high 32 bits of the FILETIME.

.
Documentation
[FILETIME] on MSDN
.

A Better Structure for VB.NET allows you to use DateTime.FromFileTime()

.

No need for a FILETIME Structure just use DateTime.FromFileTime

.

  Dim LastWrite As DateTime = DateTime.FromFileTime(ftLastWriteTime)

.

I had the same problem: DateTime.FromFileTimeUtc. Solved it using:

.

Public Structure FILETIME

.

    Return Date.FromFileTime(v + CLng(dwLowDateTime))

.
OBS
.

(Ehh - The 'FILETIME' issues seems exhausted, but I add this one, because the use of '<StructLayout(LayoutKind.Explicit)>'

.

    Public Structure FILETIME

.

        Return Date.FromFileTime(LongValue)

.

        System.Runtime.InteropServices.ComTypes.FILETIME ConnectTime;

.

        System.Runtime.InteropServices.ComTypes.FILETIME DisconnectTime;

.

        System.Runtime.InteropServices.ComTypes.FILETIME LastInputTime;

.

        System.Runtime.InteropServices.ComTypes.FILETIME LoginTime;

.

        System.Runtime.InteropServices.ComTypes.FILETIME CurrentTime;

netapi32

.

  DateTime aRebootTime = DateTime.FromFileTime(wks.StatisticsStartTime);

ole32

.
Summary
Converts the MS-DOS representation of the time and date to a FILETIME structure.
.

static extern bool CoDosDateTimeToFileTime(

.

   out FILETIME lpFileTime);

.
Documentation
[CoDosDateTimeToFileTime] on MSDN
.
Summary
Returns the current time as a FILETIME structure.
.

static extern void CoFileTimeNow(out FILETIME time);

.

FILETIME, which is defined in [System.Runtime.InteropServices] or [System.Runtime.InteropServices.ComTypes] in the .NET Framework 2.0.

.

You cannot define FILETIME as the return type, because the marshaler does not support it.

.
Documentation
[CoFileTimeNow] on MSDN
.
Summary
Converts a FILETIME into MS-DOS date and time values.
.

static extern bool CoFileTimeToDosDateTime(

.

   [In] ref FILETIME lpFileTime,

.

FILETIME, which is defined in [System.Runtime.InteropServices] or [System.Runtime.InteropServices.ComTypes] in the .NET Framework 2.0.

.
Documentation
[CoFileTimeToDosDateTime] on MSDN

Enums

.

        VT_FILETIME = 64,

advapi32

.

        public FILETIME lastWritten;

.

        public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten;

.

            public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten;

.

     //public System.Runtime.InteropServices.FILETIME lastWritten; // .NET 1.1

.

     public System.Runtime.InteropServices.ComTypes.FILETIME lastWritten; // .NET 2.0

.

     public System.Runtime.InteropServices.ComTypes.FILETIME lastWritten;

.

    public ComTypes.FILETIME PasswordLastSet;

.

    public ComTypes.FILETIME BadPasswordTime;

.

    public ComTypes.FILETIME LockoutTime;

.

   PFILETIME lpftLastWriteTime

dhcpsapi

.

    return DateTime.FromFileTime((((long) dwHighDateTime) << 32) | dwLowDateTime);

.

        return DateTime.FromFileTime((((long) dwHighDateTime) << 32) | (UInt32) dwLowDateTime);

rapi

.

            [FieldOffset(  4)] public FILETIME      ftCreationTime;

.

            [FieldOffset( 12)] public FILETIME      ftLastAccessTime;

.

            [FieldOffset( 20)] public FILETIME      ftLastWriteTime;

.

FILETIME is now obsolet. You can use System.Runtime.InteropServices.ComTypes.FILETIME type instead.

.

        Public ftCreationTime As FILETIME

.

        Public ftLastAccessTime As FILETIME

.

        Public ftLastWriteTime As FILETIME

msdelta

.

                      ref System.Runtime.InteropServices.ComTypes.FILETIME lpTargetFileTime,

.

                      IntPtr lpTargetFileTime,

Constants

.

    public static PropertyKey PKEY_Device_DriverDate = new PropertyKey(0xa8b865dd, 0x2e3d, 0x4094, 0xad, 0x97, 0xe5, 0x93, 0xa7, 0xc, 0x75, 0xd6, 2);      // DEVPROP_TYPE_FILETIME

.

    public static PropertyKey PKEY_DeviceDisplay_Last_Connected = new PropertyKey(0x78c34fc8, 0x104a, 0x4aca, 0x9e, 0xa4, 0x52, 0x4d, 0x52, 0x99, 0x6e, 0x57, 0x00000043);  // VT_FILETIME

.

    public static PropertyKey SENSOR_DATA_TYPE_TIMESTAMP = new PropertyKey(0XDB5E0CF2, 0XCF1F, 0X4C18, 0XB4, 0X6C, 0XD8, 0X60, 0X11, 0XD6, 0X21, 0X50, 2); //[VT_FILETIME]

winspool

.

        System.Runtime.InteropServices.ComTypes.FILETIME ftDriverDate;

.

        FILETIME ftDriverDate;

.

        FILETIME ftMinInboxDriverVerDate;

kernel32

.

     long duetime = dt.ToFileTime();

.
Summary
.

static extern bool DosDateTimeToFileTime(ushort wFatDate, ushort wFatTime,

.

   out UFILETIME lpFileTime);

.

    public struct UFILETIME

.

Sample and signature code originally used System.Runtime.InteropServices.FILETIME, but this uses ints instead of uints (DWORDs) meaning that this line:

.

    private static extern int DosDateTimeToFileTime(ushort dateValue, ushort timeValue, out UInt64 fileTime);

.

    private static extern int FileTimeToDosDateTime(ref UInt64 fileTimeInfo, out ushort dateValue, out ushort TimeValue);

.

        UInt64 data = Convert.ToUInt64(DateTime.Now.ToFileTime());

.

        result = FileTimeToDosDateTime(ref data, out dateValue, out timeValue);

.

        result = DosDateTimeToFileTime(dateValue, timeValue, out data);

.

       Console.Write(DateTime.FromFileTime(Convert.ToInt64(data)).ToString("MM/dd/yyyy hh:mm:ss tt"));

.

    public struct UFILETIME

.

        UFILETIME filetime = new UFILETIME();

.

        DosDateTimeToFileTime(DosDate, DosTime, out filetime);

.

        long longfiletime = (long)(((ulong)filetime.dwHighDateTime << 32) +

.

            (ulong)filetime.dwLowDateTime);

.

        return DateTime.FromFileTimeUtc(longfiletime);

.
Documentation
[DosDateTimeToFileTime] on MSDN
.
Summary
.

static extern bool FileTimeToDosDateTime([In] ref FILETIME lpFileTime,

.

        var fileTime = BitConverter.GetBytes(time.ToFileTime());

.

        var ft = new FILETIME

.

            dwLowDateTime = BitConverter.ToInt32(fileTime, 0),

.

            dwHighDateTime = BitConverter.ToInt32(fileTime, 4)

.

        FileTimeToDosDateTime(ref ft, out dosDate, out dosTime);

.
Documentation
[FileTimeToDosDateTime] on MSDN
.
Summary
.

static extern bool FileTimeToLocalFileTime([In] ref FILETIME lpFileTime,

.

   out FILETIME lpLocalFileTime);

.

FileTimeToLocalFileTime converts a time from UTC time (also known as Greenwich Mean Time) to "local time" (inside the computer's selected time zone). The source and target times are stored in FILETIME structures. The function returns 1 if successful, or 0 if an error occurs.FileTimeToLocalFileTime Converts a UTC file time to a local file time. System.DateTime.ToFileTime FileTimeToLocalFileTime Converts a UTC file time to a local file time. System.DateTime.ToLocalTime

.
Documentation
[FileTimeToLocalFileTime] on MSDN
.
Summary
.

static extern bool FileTimeToSystemTime([In] ref FILETIME lpFileTime,

.

   Friend Shared Function FileTimeToSystemTime( _

.

                        <[In]()> ByRef lpFileTime As FILETIME, _

.

FileTime and SystemTime.

.

FileTime page

.

    public static DateTime FileTimeToSystemTime(string hexTS) {

.

        FILETIME fileTime;

.

        fileTime.dwHighDateTime = int.Parse(highDT, System.Globalization.NumberStyles.HexNumber);

.

        fileTime.dwLowDateTime = int.Parse(lowDT, System.Globalization.NumberStyles.HexNumber);

.

        long hFT2 = (((long)fileTime.dwHighDateTime) << 32) | ((uint)fileTime.dwLowDateTime);

.

        return DateTime.FromFileTimeUtc(hFT2);

.

You really do not need to use this function as you could use the FromFileTime or FromFileTimeUtc on DateTime class. Refer to the sample code provided in the FileTime page.

.
Documentation
[FileTimeToSystemTime] on MSDN
.

     lastAccessTime = GetDateTimeFromFILETIME(fileData.ftLastAccessTime);

.

     lastModifiedTime = GetDateTimeFromFILETIME(fileData.ftLastWriteTime);

.

     lastAccessTime = GetDateTimeFromFILETIME(fileData.ftLastAccessTime);

.

     lastModifiedTime = GetDateTimeFromFILETIME(fileData.ftLastWriteTime);

.
Summary
.

static extern bool GetFileTime(IntPtr hFile, IntPtr lpCreationTime,

.

         Friend Shared Function GetFileTime( _

.

                        <Out()> ByRef lpCreationTime As FILETIME, _

.

                        <Out()> ByRef lpLastAccessTime As FILETIME, _

.

                        <Out()> ByRef lpLastWriteTime As FILETIME) _

.

public class GetFileTimeSample

.

    private struct FILETIME

.

    private static extern bool GetFileTime(

.

    ref FILETIME lpCreationTime,

.

    ref FILETIME lpLastAccessTime,

.

    ref FILETIME lpLastWriteTime

.

    public static void GetFileTimes(string FileName, out DateTime CreationTime, out DateTime LastAccessTime, out DateTime LastWriteTime)

.

    FILETIME ftCreationTime = new FILETIME();

.

    FILETIME ftLastAccessTime = new FILETIME();

.

    FILETIME ftLastWriteTime = new FILETIME();

.

        if (GetFileTime(ptr, ref ftCreationTime, ref ftLastAccessTime, ref ftLastWriteTime) != true)

.

        CreationTime = DateTime.FromFileTimeUtc((((long)ftCreationTime.dwHighDateTime) << 32) | ((uint)ftCreationTime.dwLowDateTime));

.

        LastAccessTime = DateTime.FromFileTimeUtc((((long)ftLastAccessTime.dwHighDateTime) << 32) | ((uint)ftLastAccessTime.dwLowDateTime));

.

        LastWriteTime = DateTime.FromFileTimeUtc((((long)ftLastWriteTime.dwHighDateTime) << 32) | ((uint)ftLastWriteTime.dwLowDateTime));

.
Documentation
[GetFileTime] on MSDN
.

static extern bool GetProcessTimes(IntPtr hProcess, out FILETIME

.

   lpCreationTime, out FILETIME lpExitTime, out FILETIME lpKernelTime,

.

   out FILETIME lpUserTime);

.

    System.Runtime.InteropServices.FILETIME ftCreation, ftExit, ftKernel, ftUser;

.

    Console.WriteLine("Creation {0}", FiletimeToDateTime(ftCreation));

.

    Console.WriteLine("Exit {0}", FiletimeToDateTime(ftExit));

.

    Console.WriteLine("Kernel {0}", FiletimeToTimeSpan(ftKernel));

.

    Console.WriteLine("User {0}", FiletimeToTimeSpan(ftUser));

.

    out System.Runtime.InteropServices.FILETIME lpCreationTime,

.

    out System.Runtime.InteropServices.FILETIME lpExitTime,

.

    out System.Runtime.InteropServices.FILETIME lpKernelTime,

.

    out System.Runtime.InteropServices.FILETIME lpUserTime);

.

public static DateTime FiletimeToDateTime(System.Runtime.InteropServices.FILETIME fileTime)

.

    ulong hFT2 = unchecked((((ulong)(uint)fileTime.dwHighDateTime) << 32) | (uint)fileTime.dwLowDateTime);

.

    return DateTime.FromFileTimeUtc((long)hFT2);

.

public static TimeSpan FiletimeToTimeSpan(System.Runtime.InteropServices.FILETIME fileTime)

.

    ulong hFT2 = unchecked((((ulong)(uint)fileTime.dwHighDateTime) << 32) | (uint)fileTime.dwLowDateTime);

.

            out FILETIME lpIdleTime,

.

            out FILETIME lpKernelTime,

.

            out FILETIME lpUserTime

.

    FILETIME idleTime, kernelTime, userTime;

.
Summary
.

static extern void GetSystemTimeAsFileTime(out FILETIME

.

   lpSystemTimeAsFileTime);

.

FileTime.

.

using FILETIME=System.Runtime.InteropServices.ComTypes.FILETIME;

.

       public static extern void GetSystemTimeAsFileTime(out FILETIME lpSystemTimeAsFileTime);

.

        FILETIME myTime = new FILETIME();

.

        GetSystemTimeAsFileTime(out myTime);

.
Documentation
[GetSystemTimeAsFileTime] on MSDN
.

            out FILETIME lpIdleTime,

.

            out FILETIME lpKernelTime,

.

            out FILETIME lpUserTime

.

    FILETIME idleTime, kernelTime, userTime;

.

The original API defined the return values as FILETIME rather than long, but long appears to be compatible with FILETIME and can be easier to deal with.

.
Summary
.

static extern bool SetFileTime(IntPtr hFile, ref long lpCreationTime, ref long lpLastAccessTime, ref long lpLastWriteTime);

.

Private Shared Function SetFileTime(ByVal hFile As IntPtr, ByRef lpCreationTime As Long, ByRef lpLastAccessTime As Long, ByRef lpLastWriteTime As Long) As Boolean

.

  public static void SetFileTimes(IntPtr hFile, DateTime creationTime, DateTime accessTime, DateTime writeTime)

.

    long lCreationTime    = creationTime.ToFileTime();

.

    long lAccessTime    = accessTime.ToFileTime();

.

    long lWriteTime        = writeTime.ToFileTime();

.

    if(!SetFileTime(hFile, ref lCreationTime, ref lAccessTime, ref lWriteTime))

.

    If Not SetFileTime(oFile_Stream.Handle, oSource_File_Info.CreationTime.ToFileTime, oSource_File_Info.LastAccessTime.ToFileTime,     oSource_File_Info.LastWriteTime.ToFileTime) Then

.
Documentation
[SetFileTime] on MSDN
.
Summary
.

static extern bool SystemTimeToFileTime([In] IntPtr lpSystemTime,

.

   IntPtr lpFileTime);

.

    //now malloc the Filetime;

.

    long lFileTime = 0;

.

    IntPtr pFileTime = Marshal.AllocHGlobal(ftLen);

.

    //call the kernal32.dll SystemTimToFileTime method

.

    SystemTimeToFileTime(pSystemTime, pFileTime);

.

    //marshal the Filetime back into managed memory

.

    lFileTime = Marshal.ReadInt64(pFileTime);

.

    // convvert filetime to System.DateTime class

.

    DateTime dt = DateTime.FromFileTimeUtc(lFileTime);

.

    Marshal.FreeHGlobal(pFileTime);

.
Documentation
[SystemTimeToFileTime] on MSDN

ntdll

.

    public static bool GetFourFileTimes(string path2file,

.

                    creationTime = DateTime.FromFileTime(fbi.CreationTime);

.

                    lastAccessTime = DateTime.FromFileTime(fbi.LastAccessTime);

.

                    lastWriteTime = DateTime.FromFileTime(fbi.LastWriteTime);

.

                    changeTime = DateTime.FromFileTime(fbi.ChangeTime);

.

        brc = Nt.GetFourFileTimes(path2file, out creationTime, out lastAccessTime, out lastWriteTime, out changeTime, out fileAttributesAfter, out errMsg);

.

MessageBox.Show(DateTime.FromFileTime(t).ToString());

Delegates

.

dwTimerLowValue [in]             The low-order portion of the UTC-based time at which the timer was signaled. This value corresponds to the dwLowDateTime member of the FILETIME structure. For more information about UTC-based time, see System Time.

.

dwTimerHighValue [in]             The high-order portion of the UTC-based time at which the timer was signaled. This value corresponds to the dwHighDateTime member of the FILETIME structure.

Interfaces

.

     public System.Runtime.InteropServices.ComTypes.FILETIME mtime;

.

     public System.Runtime.InteropServices.ComTypes.FILETIME ctime;

.

     public System.Runtime.InteropServices.ComTypes.FILETIME atime;

.

        /* [unique][in] */ FILETIME pctime,

.

        /* [unique][in] */ FILETIME patime,

.

        /* [unique][in] */ FILETIME pmtime);

.

                        ByVal pctime As FILETIME,

.

                        ByVal patime As FILETIME,

.

                        ByVal pmtime As FILETIME)

.

FILETIME

.

        [In] ref FILETIME pctime,

.

        [In] ref FILETIME patime,

.

        [In] ref FILETIME pmtime);

.

      public FILETIME mtime;

.

      public FILETIME ctime;

.

      public FILETIME atime;

.

FILETIME

coredll

.
Summary
.

[DllImport("kernel32.dll", EntryPoint = "SystemTimeToFileTime", SetLastError = true)]

.

    public static extern bool SystemTimeToFileTime(ref SYSTEMTIME lpSystemTime, ref FILETIME lpFileTime);

.

Declare Function SystemTimeToFileTime Lib "Coredll.dll" (TODO) As TODO

.

SystemTime and FileTime

.

        FILETIME ft = new FILETIME();

.

        SystemTimeToFileTime(ref st, out ft);

.
Documentation
[SystemTimeToFileTime] on MSDN

crypt32

.

        Marshal.StructureToPtr(DateTime.Now.ToFileTimeUtc(), revPara.pftTimeToUse, false);

wininet

.

    <FieldOffset(32)> Public LastModifiedTime As FILETIME

.

    <FieldOffset(40)> Public ExpireTime As FILETIME

.

    <FieldOffset(48)> Public LastAccessTime As FILETIME

.

    <FieldOffset(56)> Public LastSyncTime As FILETIME

.

    <FieldOffset(32)> Public LastModifiedTime As FILETIME

.

    <FieldOffset(40)> Public ExpireTime As FILETIME

.

    <FieldOffset(48)> Public LastAccessTime As FILETIME

.

    <FieldOffset(56)> Public LastSyncTime As FILETIME

setupapi

.

        public System.Runtime.InteropServices.ComTypes.FILETIME DriverDate;


 
Access PInvoke.net directly from VS: