I'm using Delphi 2007.
I am copying files to a remote drive. When the copying ends, I shutdown/standby the machine. It can happen that some files don't get copied from buffer to disk, and the remote disk gets disconnected, so the backup is not completed. I need to detect disk activity on that disk to properly be able to take the close action on the machine.
Is there a way to detect disk activity in this scenario?
(Please move the additional information from the comment to your question.) AFAIK there is no Windows API to tell whether all data has been written to disk.
What you are looking for is the Windows equivalent of the Unix sync command. You could run this tool from your program. Please read the information on the linked page, this requires administrative rights, and even so it may not be enough to be sure - some disk drives have a firmware that tells the OS that all writes have completed, when in fact they have not, and unwritten data is still in the on-disk-cache. You should better add a delay after your copy action has finished, to be on the safe side.
I don't remember where this came from, but it works. Unfortunately I don't know how to attach stuff here, so I cannot add the dcr with an icon.
Update: Found it on torry.net, along with plenty of other components that do the same trick: http://www.torry.net/pages.php?id=252
It depends on the type of disk activity you want to detect.
The language "Delphi" in-and-of itself probably has no libraries to help you with this.
If those don't do it for you then you need to drop down to hooking the operating system calls or more likely the hardware level which usually involves writing a device driver hooking the IDT (Interrupt Descriptor Table). I recommend the book Rootkits for more information.
Also see JvChangeNotify.TJvChangeNotify class in JCL.