PDA

View Full Version : File/folder removal


Mr. Hasselhoff
07-30-2006, 08:57 PM
Ever needed to be able to delete any file or folder even if its in use. Now you can.
This can be useful to get rid of trojan files and folders even if the trojan is running or any of the files are in use.
I will post the rest of the code necessary to use that function later along with more info about all of it.

bool newDeleteFile(LPCSTR lpFileName)
{
OBJECT_ATTRIBUTES pObj;
UNICODE_STRING uFile;
WCHAR wFile[256];

// create an UNICODE path
swprintf(wFile, L"\\??\\%S", lpFileName);

// create UNICODE_STRING
pRtlInitUnicodeString(&uFile, wFile);

// setup OBJECT_ATTRIBUTES for NtDeleteFile
InitializeObjectAttributes(&pObj, &uFile, OBJ_CASE_INSENSITIVE, NULL, NULL);
if(NT_SUCCESS(pNtDeleteFile(&pObj)))
return true;

return false;
}