![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
changes to file.
How hard would it be to implement a program to run in the background and watch a specific file to see if changes are made to it. Then to display a MessageBox when that happens. Incase its needed this will be for WinXP Pro.
I have created an Internal Support Utility for us to track support calls from our employees and saves the info in a .DAT file (data can be added, edited, or deleted). I wanted to make an extension of that by making a separate program that only allows data entry to the file to place on the users PC's. They can add a "service call" and I would like to know when an addition is made. I know I could just open the program and look at the file to see if there are any new entries. But I believe it would be much more efficient if a notification was presented when a change was made. How hard would this be to do. Or is it even possible? Thanks, -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
You can check the time stamp of the file. It should be fairly simple.
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
Yes, it is possible...Pizentios and I were working on a similar script, written in Perl, for Linux yesterday.
I modified that script a bit to end up with a monitoring script to notify me when a file changes, in which the changes include certain keywords. It is basically just 'tail'ing the file and parsing the lines. There is about a 10 second turn-around-time... Works fine in Linux, haven't tested it in Windows, but with a bit of modification you should be able to get it to work in Windows or at the very least, take the logic and apply it to a more "windows friendly" language. #!/usr/bin/perl
use File::Tail;
$name = "/var/log/nogo.log";
$keyword = "denied";
$file=File::Tail->new(name=>$name, maxinterval=>10, adjustafter=>7);
while (defined($line=$file->read))
{
$check = index($line, $keyword);
if ($check > 0)
{
print "[WARNING]: Unauthorized Access. -> $line\n";
}
}Edit: InfoGeek's idea would probably be an easier solution in Windows. Just create a program that will check the file's timestamp, if it has been modified X minutes from specified interval, then send a notification. You could put the program in a scheduled task to make it repeat on a certain time during the day.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
Under Windows you can also use the directory change notification functions documented here
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
hmm.. I'll look into that.
Thanks, -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Ok I've got a question regarding FindFirstChangeNotification...
It says when it fails it returns INVALID_HANDLE_VALUE. I guess I don't understand what it returns when it is successful but does not find a change. Or would that be a failure? ![]()
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
If I send you for a gallon of milk and you can't find any, is that a failure? If there is none to be found, is that a failure?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#8 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Have you fully read this page? If so you must have tried to use GetLastError. What did that return?
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#9 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
Quote:
When you use this function, you don't have to poll for changes every so often, you just set up the notification, then call the wait function, when the wait function returns, a change has happenned. This way, your program doesn't take any CPU while waiting. |
|
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Well, I got the program working. It was surprisingly easy. I think I was trying to make it harder than what it was.
Thanks for all the help. -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|