Check File if updated or not..??

Hi,

        I want to creat a visual basic application that will check whether a particular file has been updated/changed. For eq. The application will check whether a file temp.log has been updated/changed in folder c:\Test or not. How can i make this exe to sit on the computer througou the time when the system starts up. Should i make this exe as a Service. Can i have this .exe running constantly in the system tray, so that it keeps on checking for the particular .log file.

Any help about how to begin on this will be highly appreciated.

Thanks


b_harpalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
Hi b_harpal,

Here is some sample code which will allow VB to respond to changes in the file system: you can either run this as a service (providing it has access to the appropriate folders) or if you want as an application launched either from the startup menu or by the HKLM\.....\Run key in the registry.

Private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4
Private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2
Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
Private Const FILE_NOTIFY_CHANGE_SIZE = &H8
Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10
Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100
Private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100
Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function ResetEvent Lib "kernel32" (ByVal hEvent As Long) As Long
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As Long
    'Set the notification hook
    Ret = FindFirstChangeNotification("C:\", &HFFFFFFFF, FILE_NOTIFY_CHANGE_ALL)
    'Wait until the event is triggered
    WaitForSingleObject Ret, &HFFFFFFFF
    MsgBox "Event Triggered for the first time"
    'Reactivate our hook
    FindNextChangeNotification Ret
    'Wait until the event is triggered
    WaitForSingleObject Ret, &HFFFFFFFF
    MsgBox "Event Triggered for the second time"
    'Remove our hook
    FindCloseChangeNotification Ret
End Sub

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Renato102098Commented:
'You add reference to Microsoft Scripting Runtime
'In new form put Commmand Button and paste this code.

Private Sub Command1_Click()
Dim Creado As String, Accedido As String, Modificado As String
Dim fso As New FileSystemObject, F As File
Set F = fso.GetFile("C:\Test\temp.log ")
Creado = "Unknow"
Accedido = "Unknow"
Modificado = "Unkow"
On Error Resume Next
    Creado = F.DateCreated
    Accedido = F.DateLastAccessed
    Modificado = F.DateLastModified
On Error GoTo 0
MsgBox "Created " & Creado & vbCrLf & "Modified " & Modificado & vbCrLf & "Acessed " & Accedido
End Sub
0
b_harpalAuthor Commented:
Timcottee,

When i run ur code, it runs sumtimes but it hangs most of the times.
Also what i want here is that this application will always keep running and check the particular file and never come out. Like if it finds the file has been updated it will run a batch file and again keep checking and see if again updated or not...so on..

Renato, im tyring ur option too..lets wait & see..

Thanks
harry
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.