how to track file changes and registry changes to the system? - windows

hi guys i have a test system at work which is used to test final builds. I am wondering if there is a way to track if someone dumps a file on the system... I don't care if it tracks it for entire system or a specific directory any ideas?

Use FileSystemWatcher Class. It looks for different changes in folder.

Related

Trying to create a script to change settings on Plantronics hub

I’m new to the IT industry but keen to learn.
Wanted to ask if anyone could point me in the right direction when trying to create a Powershell script to change settings within a computer app called plantronics hub.
Just need a better insight to what commands I need to use and functions. Just so that instead of going to a users machine every time and changing the settings I can just run a script and let it do it for me.
There are a few things you can look at. Look through the program files to see if there's any kind of command line utility for this sort of thing. Obviously, documentation is another good place to look. If available, you can also call their support and simply ask. Keep in mind they may have already considered this scenario, and may have other suggestions.
Try and figure out how the application stores its settings, Registry, XML, ini file etc...? PowerShell can work with any of these, but you need to answer this question before knowing what direction to go it.
If the settings are in the registry I'd start looking under HKLM:/ & HKCU:\Software\Plantronics. Settings and/or configuration files may be in the program files folder or under the user profile app data folders.
A few techniques:
Export the registry, make a configuration change, export the registry again to a different file. Compare the 2 files via some file comparison tool, like BeyondCompare or WinMerge. This might help you find anything that changed after you made the change.
Use procmon.exe . If you filter it properly you can determine which files the application is touching either on start or when you make a configuration change. ProcMon can also help identify which registry keys and values are being looked at.
Note: If the settings are consistent between stations you may be able to copy the config. This could be as simple as a file copy or importing a registry file.

File watcher in shell

I am trying to keep two directories synchronized with the same files in them.
Files are dropped into Directory A throughout the day. I would like to create a file watcher script that will copy files from Directory A to Directory B as soon as they are dropped.
My thought was to run the job every minute and simply copy everything that dropped in the last minute, but I am wondering if there is a better solution out there.
I'm running MKS toolkit under Windows. Different servers, same operating system.
Thanks for your help!
If you use Linux, you can hook into the kernel using the inotify API to get notified if something in a folder changes. There are command line versions like inotifywatch(1) as well.
To copy the files, I suggest to use rsync(1): it is clever, knows how to clean up after itself and it will create new files hidden while they are copied so users and programs are less likely to pick them up before they are complete.

Watch directory for file changes

I want to monitor a directory (of thousands of files, with about 5 levels of sub directories) for when files are changed. I know I can use the FSEvents API to monitor a directory for when files change inside that directory, but I can't seem to figure out how to determine which file(s) changed. This reference suggests I build a binary tree and traverse the tree each time an event is triggered, is that the best way to determine which files were changed? If not, what are some better alternatives?
Is it better to recursively scan the directory and attach kqueue to every file? I'm not sure how well that would work on thousands of files?
I've used UKKQueue before with mixed results.
I've recently become aware of a better solution, but I haven't tried this. If you only need to target Lion, I think that the new best-practice way to do this is to use an NSFileCoordinator. You implement the methods of NSFilePresenter to indicate which directory you're interested in (the presentedItemURL property) and the system will notify you when a sub item moves/changes/is deleted (via methods like presentedSubitemDidChangeAtURL:)
I'd love to hear how that works out if you do go that route.
If you create your stream using kFSEventStreamCreateFlagFileEvents then you will get events for the changes to each file rather than just a notification of the change to the watched directory. Unfortunately this is only available in OSX 10.7 and later.

Synchronize file system with object hierarchy

Are there any patterns or best practices for keeping a hierarchy of objects consistent with the file system?
Each object corresponds with a file on the file system. Files can be added, changed, deleted etc and the object hierarchy should be adapted accordingly.
Please don't answer along the lines of "discard files, use a database".
A good starting point is to check how the target OS lets you watch the filesystem. On Linux there's the inotify API. On Windows you wait on the notification handle created by the FindFirstChangeNotification() API call. Both let you avoid active polling of the directory for changes.

How to mimic DropBox functionality with Ruby script?

I would like to upload documents to GoogleDocs every time the OS hears that a file was added/dragged/saved in a designated folder, just the way DropBox uploads a file when you save it in the DropBox folder.
What would this take in Ruby, what are the parts?
How do you listen for when a File is Saved?
How do you listen for when a File is added to a Folder?
I understand how to use the GoogleDocs API and upload things once I get these events, but I'm not sure how this would work.
Update
While I still don't know how to check if a file is added to a directory, listening for when a file is saved is now dirt simple, thanks to Guard for ruby.
If I were faced with this, I would use something like git or bzr to handle the version checking and just call add then commit from your script and monitor which files have changed (and therefore need to be uploaded).
This adds the benefit of full version control over files and it's mostly cross platform (if you include binaries for each platform).
Note this doesn't handle your listening problem, just what you do when you know something has changed. You could schedule the task (via various routes) but I still like the idea of a proper VCS under the hood.
I just found this: http://www.codeforpeople.com/lib/ruby/dirwatch/
You'd need to read over it as I can't vouch for its efficiency or reliability. It appears to use SQLite, so it might be better just to manually check once every 10 seconds (or something along those lines).
Ruby doesn't include a built-in way to "listen" for updates to files. If you want to stick to pure Ruby, your best bet would be to perform the upload on a fixed schedule (say every 5 minutes) regardless of when the file is saved.
If this isn't an acceptable alternative, you could try writing the app (or at least certain parts of it) in Java, which does support this type of thing. Take a look at JRuby for integrating the Ruby and Java portions of your app.
Here is a pure ruby gem:
http://github.com/TwP/directory_watcher
I don't know the correct way of doing this, but a simple hack would be to have a script running in the background which checks the contents of a bunch of folders every n minutes and uses the associated timestamps to determine if the file was modified in that span of time
You would definitely need some native OS code here, to write the monitoring service/client. I'd select C++ if you want it to be cross platform. If you decide to go with .Net, for example, you can use the FileSystemWatcher class to achieve what you need (documentation and here's a related article).
Kind of an old thread, but I am faced with doing something similar and wanted to throw in my thoughts. The route I'm going is to have a ruby script that watches a given directory and checks the timestamps. Once all files have been uploaded, the script saves the latest timestamp and then polls the directory again, checking if any files/folders have been added. If files are found, then the script uploads them and updates the global timestamp, etc...
The downside is that setting up a ruby script to run continually (or as a service) is somewhat painful. But it's not an overwhelming task, just needs to be thought out properly.
Also depends on if your users are competent enough to have ruby installed or if you have to package everything up into a one-click installer as well. That, to me, is the hardest part to figure out.

Resources