Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 12th, 2006, 10:03 AM   #1
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Old May 12th, 2006, 10:08 AM   #2
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
You can check the time stamp of the file. It should be fairly simple.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old May 12th, 2006, 10:14 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old May 12th, 2006, 12:04 PM   #4
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
Under Windows you can also use the directory change notification functions documented here
The Dark is offline   Reply With Quote
Old May 12th, 2006, 3:50 PM   #5
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
hmm.. I'll look into that.

Thanks,
-BB98
__________________
Learning to use C++ and loving every minute of it.
badbasser98 is offline   Reply With Quote
Old May 12th, 2006, 4:34 PM   #6
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Old May 12th, 2006, 4:55 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old May 12th, 2006, 5:16 PM   #8
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old May 12th, 2006, 7:41 PM   #9
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
Quote:
Originally Posted by badbasser98
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?
The FindFirstChangeNotification function does not check for changes immediately, it creates a handle to an object that you can "wait" for using the WaitForSingleObject or WaitForMultipleObject functions. When the wait function returns, then either a change has happenned, or a timeout has occurred.
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.
The Dark is offline   Reply With Quote
Old May 17th, 2006, 9:08 AM   #10
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC