I've been working for a .Net app/program in VB 2008 that will backup/copy file(s) and Folder(s) with the specified path. My Brother tested it and he found out that when the app try to Copy a file that is currently in used by the Other Process , it returns an error that it was currently used. therefore the Copy Procedure will fail.
My Objective is to Close the 'Handle' of the process that is currently using the File
Example is the SQL Server. when the Service is running , the Database file, the .mdf and .ldf file is LOCKED. when the app try to copy the file and fail at first , the app will make a way to copy the file bye closing the handle of the other process(s) in that file , then when all Handle(s) are closed , the app will try to copy it again.
I'm currently trying my best but I'm stock , I already use the Low-Level API NtQuerySystemInformation to Enumerate the Handles in the System, but still far from my Objective. I should determine what type of Handle is being enumerated, and then if the app knew that is was a File Handle , then it will check if it was the Target File Handle , then determine the owner of the handle , then obtain a handle to the Owner of the Handle , the Owner's Handle returned by OpenProcess Function of Kernel32 will be used to Call CreateRemoteThread then the Function to be execute by the Remote Thread is use To Close the Target File Handle.
But this is only my idea. I don't know if this will work. Actually I'm stock in the part where I want to determine what is the type of the Handle.
Please help me, I hope someone know the solution. :(