Solved

Change Modified Date On System Files?

Posted on 2001-07-12
9
190 Views
Last Modified: 2011-08-18
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)
0
Comment
Question by:magoo2
9 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6278783
Reinstall everything with the date set to the current date is the only way, SORRY

-Dave
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6278919
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.
0
 
LVL 3

Accepted Solution

by:
andysalih earned 200 total points
ID: 6278971
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, _
    FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, _
    OPEN_EXISTING, 0, 0)
   
lRet = SetFileTime(lFileHnd, ByVal 0&, ByVal 0&, _
         typFileTime)

CloseHandle lFileHnd
SetFileDateTime = lRet > 0

End Function


does what you want it to do

hope this helps

andy
0
 
LVL 1

Expert Comment

by:khampton
ID: 6279523
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).
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6279981
Andy has the answer.

Used this bit of code before

Vin.
0
 
LVL 1

Expert Comment

by:khampton
ID: 6281387
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.
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6281886
Hi!

Here's a file over the net for you:

Download...
http://www.vb-helper.com/Howto/setftime.zip

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

That's it!

glass cookie : )
0
 
LVL 3

Expert Comment

by:andysalih
ID: 6283559
anybody alive on this one
0
 
LVL 1

Author Comment

by:magoo2
ID: 6296704
Hi,

 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!

 Magoo
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now