?
Solved

Check File if updated or not..??

Posted on 2003-03-07
3
Medium Priority
?
145 Views
Last Modified: 2010-04-07
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


0
Comment
Question by:b_harpal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 total points
ID: 8087232
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
 
LVL 1

Expert Comment

by:Renato102098
ID: 8088038
'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
 

Author Comment

by:b_harpal
ID: 8093548
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Suggested Courses

770 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