Change Modified Date On System Files?

Hi all,

 After installing SP5 on my computer , I found that some dummy(me) had set the clock to year 2010 instead of 2001.

 Of course this set all the installed file's dates to 2010. How do I change the modified date on system files to reflect the present date?

 Thanks for any help!

 Magoo (aka mr swooft typer)
Who is Participating?
andysalihConnect With a Mentor Commented:
cut and paste this

Option Explicit
 Private Type FILETIME
     dwLowDate  As Long
     dwHighDate As Long
 End Type
 Private Type SYSTEMTIME
     wYear      As Integer
     wMonth     As Integer
     wDayOfWeek As Integer
     wDay       As Integer
     wHour      As Integer
     wMinute    As Integer
     wSecond    As Integer
     wMillisecs As Integer
 End Type
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_WRITE = &H40000000
Private Declare Function CreateFile Lib "kernel32" Alias _
   "CreateFileA" (ByVal lpFileName As String, _
   ByVal dwDesiredAccess As Long, _
   ByVal dwShareMode As Long, _
   ByVal lpSecurityAttributes As Long, _
   ByVal dwCreationDisposition As Long, _
   ByVal dwFlagsAndAttributes As Long, _
   ByVal hTemplateFile As Long) _
   As Long

Private Declare Function LocalFileTimeToFileTime Lib _
     "kernel32" (lpLocalFileTime As FILETIME, _
      lpFileTime As FILETIME) As Long

Private Declare Function SetFileTime Lib "kernel32" _
   (ByVal hFile As Long, ByVal MullP As Long, _
    ByVal NullP2 As Long, lpLastWriteTime _
    As FILETIME) As Long

Private Declare Function SystemTimeToFileTime Lib _
    "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime _
    As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" _
   (ByVal hObject As Long) As Long

Public Function SetFileDateTime(ByVal FileName As String, _
  ByVal TheDate As String) As Boolean
'PURPOSE:    Set File Date (and optionally time)
'            for a given file)
'PARAMETERS: TheDate -- Date to Set File's Modified Date/Time
'            FileName -- The File Name

'Returns:    True if successful, false otherwise
If Dir(FileName) = "" Then Exit Function
If Not IsDate(TheDate) Then Exit Function

Dim lFileHnd As Long
Dim lRet As Long

Dim typFileTime As FILETIME
Dim typLocalTime As FILETIME
Dim typSystemTime As SYSTEMTIME

With typSystemTime
    .wYear = Year(TheDate)
    .wMonth = Month(TheDate)
    .wDay = Day(TheDate)
    .wDayOfWeek = Weekday(TheDate) - 1
    .wHour = Hour(TheDate)
    .wMinute = Minute(TheDate)
    .wSecond = Second(TheDate)
End With

lRet = SystemTimeToFileTime(typSystemTime, typLocalTime)
lRet = LocalFileTimeToFileTime(typLocalTime, typFileTime)

lFileHnd = CreateFile(FileName, GENERIC_WRITE, _
    OPEN_EXISTING, 0, 0)
lRet = SetFileTime(lFileHnd, ByVal 0&, ByVal 0&, _

CloseHandle lFileHnd
SetFileDateTime = lRet > 0

End Function

does what you want it to do

hope this helps

Reinstall everything with the date set to the current date is the only way, SORRY

You could try opening each one in code and then closing them. That might count as modified. Or you could open them, read a byte, write it back to the file, then close them.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

The easy fix might be to change your system date to the correct (current date), move all desired files to a temp folder then copy them back to where they should be.

If you search MSDN, you will see that there is a bug that causes the last modified date on the directory to change when you copy files...(sometimes).
Andy has the answer.

Used this bit of code before

I agree that Andy's code will change the file date and it may be the only way to fix your problem.  But my suggestion is at least worth a try.  It may not work but if it does, it will be a much easier solution.

Here's a file over the net for you:


Description: Set a file's creation, last access, and last modified times (4K)

That's it!

glass cookie : )
anybody alive on this one
magoo2Author Commented:

 Sorry to take so long getting the points to you Andy. The code works like a charm. Thanks a lot!

 Thanks to all for the comments also!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.