Solved

Change Modified Date On System Files?

Posted on 2001-07-12
9
187 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

16 Experts available now in Live!

Get 1:1 Help Now