Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

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


0
b_harpal
Asked:
b_harpal
1 Solution
 
TimCotteeCommented:
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
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now