Skip to content

Instantly share code, notes, and snippets.

@kevingosse
Last active March 23, 2024 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevingosse/5dc76124ca986a41f1e8719c77b7987a to your computer and use it in GitHub Desktop.
Save kevingosse/5dc76124ca986a41f1e8719c77b7987a to your computer and use it in GitHub Desktop.
#include <iostream>
#include <windows.h>
#include <processsnapshot.h>
int main()
{
auto processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 40092);
if (processHandle == nullptr)
{
std::cout << "Failed to open process\n";
return 1;
}
HPSS snapshotHandle;
auto result = PssCaptureSnapshot(processHandle, PSS_CAPTURE_HANDLES, 0, &snapshotHandle);
if (result != ERROR_SUCCESS)
{
std::cout << "Failed to capture snapshot\n";
return 1;
}
PSS_HANDLE_INFORMATION handleInfo;
result = PssQuerySnapshot(snapshotHandle, PSS_QUERY_HANDLE_INFORMATION, &handleInfo, sizeof(handleInfo));
if (result != ERROR_SUCCESS)
{
std::cout << "Failed to query snapshot\n";
return 1;
}
std::cout << "Handle count: " << handleInfo.HandlesCaptured << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment