I'm using Borland C++ Builder for a project which connects to a database.
There is a configuration which does backups to a USB drive. The problem with the current approach is that the drive is manually configured by the end user and sometimes things get messed up. E.g. People move the USB drive to a different port, get a different letter and then the back up process no longer works. As a side note, we have other "better" processes for backing up to the cloud, etc., however some locations don't have internet access and aren't running on a RAID... so backing up to USB gives them a saving grace from a HD crash.
I'm hoping to do some coding to help remove this issue. I'm hoping to be able to get a handle to the OS (Windows 8/7/XP) and be able to identify the drives on the machine. Once I have those, I can then iterate through them and check for a path location (e.g. File marker, so if a the file exists, I know its the USB we supplied). Then once I have that, I can do the back up.
As a worse case scenario, I will be able to iterate through all 26 letters to test each drive. However I'm using this as a learning opportunity and hoping to get a handle to the OS so reduce the number of checks/fails I can run into. Besides, I'm curious if anyone has a better approach :)
I don't think there's much to be gained by trying to do something more advanced than iterating over the 26 drive letters.
Before attempting to check whether or not the marker path exists you could add a call to GetDriveType and compare the return value against DRIVE_REMOVABLE. This will make sure that your code doesn't spin up the CD/DVD drive, or hit the network in the case of a mapped share.
Related
I want to create an application or modify USB in a way so that, upon insertion into any PC, I can get the information that PC was inserted.
eg. upon insertion, I can read PC name and make an API call with this as post data so I'm able to know that my USB was inserted in some PC. But this should happen right away as USB is read by the machine, so even if the user formats it thereafter, it should not matter.
If it was earlier windows, I could write autorun and that would work. But I want this detection mechanism for Windows 7 and above.
I have done some research on the topic but could not find any reliable content. Some articles were related to USB based hacking attacks by changing wiring (USB hardware, to harm the computer) or something like that. But I totally don't want to do that. Just the detection, that USB was used.
I am developing an OSX application that among other things shows mounted volumes as they appear/disappear. I do that using the disk arbitration framework. When I connect my computer to a network drive that I have configured as my time machine backup then a volume appears with the name "timemachine", i.e. the CFDictionary of the appearing device is this:
{DAVolumeMountable=true, DAVolumeNetwork=true, DAVolumeName=timemachine, DAVolumePath=file://localhost/Volumes/timemachine/, DAVolumeKind=afpfs}
I don't want this volume to appear in my application's UI. What criterion can I use to know it is really a time machine volume to exclude it? Just using the name or path seems weird. Wouldn't a drive formatted to have the name "timemachine" theoretically be mounted under the same name/path?
Any advice appreciated.
I don't find an API that identifies Time Machine volumes. You could call out to the tmutil program with the destinationinfo verb. I also see files such as ".com.apple.timemachine.donotpresent" on my Time Machine volume, although that's relying on undocumented implementation details.
By the way, a Time Machine volume can still be used as normal by the user. At least a local one can. They can browse into it and put other files on it besides their backup. Obviously, they shouldn't put anything there that they would be sorry to lose if a drive fails.
If you only want to show the same volumes as are present in the Finder, I would recommend using NSWorkspace and its NSWorkspaceDidMountNotification and NSWorkspaceWillUnmountNotification notifications to learn when volumes are mounted and unmounted. Use -[NSFileManager mountedVolumeURLsIncludingResourceValuesForKeys:options:] with NSVolumeEnumerationSkipHiddenVolumes. You might want to use -getResourceValue:forKey:error: with NSURLVolumeIsBrowsableKey, too, since I'm not sure that non-browsable is synonymous with hidden.
I tried to install windows7 from USB according to the instructions of following page.
http://www.intowindows.com/how-to-install-windows-7vista-from-usb-drive-detailed-100-working-guide/
But at the location where i select the partition it says me something like "device not found."(Cant give the exact machine as i came to somewhere else to search the internet, coz my machine's not working).
How can i overcome this?? I've formatted the whole disk. Got nothing to do now!!!
You have formatted the whole hard disk. That is the problem. It's a windows 7 specific problem. I'll describe the case in brief. the setup detects your pen drive as a part of the hard disk(at least something like this). Therefore you can overcome the issue by not letting this to happen.
Which means, you can make the pen drive read only (or make don't allow setup to use pen drives storage). One possible solution will be fill the empty space of the pen drive with bulky data. then there will be no space for the setup program to use in the pen.
Or else you can remove pen drive at the time where the setup is trying to access it (for the above mentioned purpose). How to know the exact time??? well it's trial and error. I myself have done it and it worked. It will require some Patience.
Of course, you can install some other os and then try install win7 after that.
Hope that helps..!!
I am in the middle of writing a tool that finds lost files of an iTunes library, for both Mac and Windows. On the Mac, I can quickly find files by naming using the wonderful "CatalogSearch" function.
On Windows, however, there seems to be no OS API for searching by file name (or is there?).
After some googling, I learned that there are tools (like TFind, Everything) that read the NTFS directory directly and scan it to find files by name.
I would like to do the same, but without having to start from scratch (although I've written quite a few disk tools in the past, I've never had the energy to dig into NTFS).
I wonder if there are ready-made libs around, possibly as a .dll, that would give me this search feature: Pass in a file name, get back its path.
Alternatively, what about the Windows indexing service? At least when I tried this on a recently installed XP Home system, the Search operation under the Start menu would actually scan all directories, which suggests that it has no complete database. As I'm not a Windows user at all, I wonder why this isn't working.
In the end, the complete solution I need is: I have a list of file names to find, and I need code that searches the entire disk (or uses a DB for it) to get me all results in one go. E.g, the search should not start a new full scan for every file I'm looking up. That's why I think the MFT way would be optimal, as it could quickly iterate over all names, comparing each to my list.
The best way to solve your problem seems to be by using the Windows Change Journal.
Problem: If it is not enabled for a volume or the volume is a non-NTFS you need a fallback (or enable the Change Journal if it is NTFS). You need administrator rights as well to access the Change Journal.
You get the files by using the FSCTL_ENUM_USN_DATA and DeviceIOControll with LowUsn=0. This directly accesses the MFT and writes all filenames into the supplied buffer. Because it sequentially acesses the MFT it is faster than the FindFirstFile API.
I want to move my program to USB memory stick. It will run only on memory stick and would not be copied (written on C# and has nearly 3GB of database).
Where can I find a good source for that and/or how can I do that?
What you described can't reasonably be done. If a user can run the program, they can run it. It doesn't matter whether they loaded it from your USB stick or not. You can write it such that it assumes it's being run from the USB stick (with relative paths, per #Kos's comment) but that will in no way prevent people from copying it to their hard drives and running it. Since you don't know where a USB stick will be mounted ahead of time, you can't even use absolute paths.
Allow me to disagree with nmichaels, it is possible to check in C# if your running from removable storage or hard drive.
Check this thread: How to detect if any specific drive is a hard drive?
However, it would be too easy to reverse the thing and allow it to run on hard drives.
As an additional protection, you can read the USB drive serial and if it doesn't match, kill the program.
OR... you if want to be hardcore, use a specific USB drive model, and read the VID/PID, or the chip itself (check mass production tool).
In the end, if the program worths it, someone would still reverse it and break the protection scheme :)