Solved

Detect a file change

Posted on 1997-09-05
7
750 Views
Last Modified: 2012-08-13
How to detect a file has been changed using something like a shell extension or a hook...

(I don't want a TTimer with constantly checking if a file's date is any different)
0
Comment
Question by:kolarb
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
For what do you want to know the change of the file?
 Progressbar for copy of file?

Why has it be checked the whole time?
0
 
LVL 3

Expert Comment

by:mirek071497
Comment Utility
You can do  this with setting Notification but only in WindowsNT. In WIndows95 this is impossible and you must use timer.

For WinNT i can write simple code.
0
 
LVL 2

Author Comment

by:kolarb
Comment Utility
ZifNab: When a user changes a file a program should be run. It is known which files should be looked at.

mirek: ?? check examples/demos/shellext examples in Delphi3. I thought something like that should be possible. Anyway show me your NT code and I'll reconsider your answer.
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 1

Expert Comment

by:arh
Comment Utility
As far as i know, there is no shell extension of this kind. But there is a pair of API functions - FindFirstChangeNotificaion/FindNextChangeNotification, available in both win95 and NT, which will notify you when any file in a particular directory has been changed. You should determine which particular file in that directory was changed by examining its date/time or something like that.
And to receive such notification your program should be running
constantly in background.
Sorry, i can't give you an example now.
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 100 total points
Comment Utility
Thanx to arh !!!!

As "arh" write i try test if notification works on Win95.
I found so yes but with some limitations. I don't have enought time to test what working and what not working but this example working.

var stop : boolean;

procedure TForm1.Button1Click(Sender: TObject);
var
  dwWaitStatus   : DWORD;
  dwChangeHandle : THandle;
begin
  Stop := False;
  dwChangeHandle := FindFirstChangeNotification(
    'C:\',                        //  directory to watch
    FALSE,                        // do not watch the subtree
                                  // in Win95 You can't set this to true !!!!
    FILE_NOTIFY_CHANGE_DIR_NAME); // watch filename changes

  if dwChangeHandle=INVALID_HANDLE_VALUE then
    begin
      ShowMessage('I can''t set notification' );
      ExitProcess(GetLastError)
    end;
  while (stop=false) do
  begin
    dwWaitStatus := WaitForSingleObject(dwChangeHandle, 100);
    if dwWaitStatus=WAIT_OBJECT_0 then
      begin
        Memo1.Lines.Add( 'File Created, Renamed or Deleted in C:\' );
      //here you can compare previous list of files with current list of files
      //and find what was changed
        if FindNextChangeNotification(dwChangeHandle)=FALSE then
        begin
          ShowMessage('I can''t restart notification' );
          ExitProcess(GetLastError);
        end;
      end;
    Application.ProcessMessages;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Stop := True;
end;



0
 
LVL 2

Author Comment

by:kolarb
Comment Utility
Excellent!
Will try it now and grade the answer.
0
 
LVL 2

Author Comment

by:kolarb
Comment Utility
Thank you guys&gals.
Searched the MSDN and found this example with other settings.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

10 Experts available now in Live!

Get 1:1 Help Now