Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Handles of a given file

Featured Replies

Posted

I am designing a delete function for a file manager i am coding however, i want to be able to delete a file even if you get that stupid windows "cant not delete due to blah" message. programs like unlocker. http://ccollomb.free.fr/unlocker/ search for all open handles for a given file and close them how is this acheived? i know after all handles are closed the obvious DeleteFileA is callled to delete the file.

example, file1.txt has handle 1 and handle 2 open.

search and find the handes CloseHandle(1) close handle(2)

deleteFileA(file.txt);

Delphi prefered but would settle with other langs and convert my self.

TIA

Hi,

1- Enumerate all processes opened handles via NtQuerySystemInformation .

2- Query all returned handles and check if it belogs to the victim file .

3- Close the victim file handles via NtDuplicateObject + DUPLICATE_CLOSE_SOURCE .

4- Delete the file .

Or :

You can modify the filesystem directly and delete the file entry .

Good luck,

[GM]

  • Author

thank you for your reply, i will try the first method you mentioned :P howerver could you explain more about the second method.

Hello,

Every file is represented as an entry in the filesystem on physical disk, the referred method is achieved by 1st knowing the filesystem type of the partition (NTFS/FAT32/FAT12 .. etc) .

Second you need to walk through the files entries and manipulate it by directly writing data to the disk and mark the victim file entry as "deleted", this depends on the filesystem type .

You can start from here :
/>http://www.ntfs.com/

Good luck,

[GM]

  • 4 weeks later...

I once did something similar using a GetFileSize loop, but you will need to know the size of the file you are trying to obtain the handle for.

I am not sure if this will work, I am not even sure if my code will work but maybe you can use the idea. I think can convert the code to delphi easily enough.


int i, filesize;
int expected_file_size=1234; // The size of he file you are looking forfor (i=0; i < 65536; i++)
{
filesize = GetFileSize(i, NULL);
if (filesize == expected_file_size)
{
break;
}
}
CloseHandle(i);

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.