V
V
Vadim Ushakov2021-10-03 09:28:38
Windows
Vadim Ushakov, 2021-10-03 09:28:38

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);
            }
        }
    }


But it does not compile due to unknown structures (types).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2021-10-03
@Nightmare1

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 question

Ask a Question

731 491 924 answers to any question