Answer the question
In order to leave comments, you need to log in
How to get a list of active files in windows?
Interested in getting a list of active (busy) files in the Windows.h system. I read about an undocumented function, here is the code
SYSTEM_HANDLE_INFORMATION* pInfo = NULL;
DWORD dwSize = 0;
NTSTATUS status = 0;
do
{
// keep reallocing until buffer is big enough
status = NtQuerySystemInformation(SystemHandleInformation, pInfo, dwSize, &dwSize);
if (status == STATUS_INFO_LENGTH_MISMATCH)
pInfo = (SYSTEM_HANDLE_INFORMATION*)realloc(pInfo, dwSize);
} while (status != 0);
for (DWORD i = 0; i < pInfo->dwCount; i++)
{
if (pInfo->handles[i].ProcessID == GetCurrentProcessId() && pInfo->handles[i].HandleType == 28)
{
TCHAR szPath[MAX_PATH];
GetFinalPathNameByHandle((HANDLE)pInfo->handles[i].HandleNumber, szPath, MAX_PATH, 0);
if (_tcsstr(szFilePath, L"filename_I_want_to_delete"))
{
CloseHandle((HANDLE)pInfo->handles[i].HandleNumber);
DeleteFile(szPath);
}
}
}
Answer the question
In order to leave comments, you need to log in
first search on SYSTEM_HANDLE_INFORMATION
https://www.cyberforum.ru/win-api/thread315092.html
3rd
https://www.codeproject.com/Articles/18975/Listing...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question