Get GDI handles by process
Get GDI handles by process

This script requires Powershell 3.0

This script get the number of GDI handles by process

Script :

$global:sig = @'
[DllImport("User32.dll")]
public static extern int GetGuiResources(IntPtr hProcess, int uiFlags);
'@

Get-Process | select ProcessName -Unique | ? {$_.processname -notmatch "Idle|System|svchost"} | % {
	Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32
	$handle = @(Get-Process -Name $_.processname )[0].Handle
	$numGuiHandles = [Win32.NativeMethods]::GetGuiResources($handle, 0)
	write-host "Number of GUI handles $numGuiHandles for " $_.processname
}

Reference : http://msdn.microsoft.com/en-us/library/windows/desktop/ms724291(v=vs.85).aspx

GDI objects support only one handle per object. Handles to GDI objects are private to a process. That is, only the process that created the GDI object can use the object handle.
There is a theoretical limit of 65,536 GDI handles per session. However, the maximum number of GDI handles that can be opened per session is usually lower, since it is affected by available memory.

> Windows 2000: There is a limit of 16,384 GDI handles per session.

There is also a default per-process limit of GDI handles. To change this limit, set the following registry value:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\GDIProcessHandleQuota
This value can be set to a number between 256 and 65,536.

> Windows 2000: This value can be set to a number between 256 and 16,384.

Get GDI handles by process

2 thoughts on “Get GDI handles by process

  • December 29, 2022 at 12:44 pm
    Permalink

    Howdy! Would you mind if I share your blog with my zynga group?
    There’s a lot of folks that I think would really enjoy your content.
    Please let me know. Many thanks

    Reply
    • January 7, 2023 at 6:19 pm
      Permalink

      yes no problem 🙂

      Reply

Leave a Reply

Your email address will not be published.