From 425430a3dcc84603a5b1ab3b82e04658c0b72edf Mon Sep 17 00:00:00 2001 From: Christian Pohle Date: Sat, 20 Mar 2021 07:22:45 +0100 Subject: [PATCH] Initial Release of GDI Check --- ActiveFax/GDI/gdi.cmd | 8 ++++++++ ActiveFax/GDI/gdi.ps1 | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 ActiveFax/GDI/gdi.cmd create mode 100644 ActiveFax/GDI/gdi.ps1 diff --git a/ActiveFax/GDI/gdi.cmd b/ActiveFax/GDI/gdi.cmd new file mode 100644 index 0000000..7121275 --- /dev/null +++ b/ActiveFax/GDI/gdi.cmd @@ -0,0 +1,8 @@ +rem : Call GDI Check +rem : With this batch it is easier to call it from a scheduled Task +rem : +rem : v1.0 - 20.03.2021 - Initial Release + +rem : Open PowerShell and run Script + powershell -ExecutionPolicy ByPass -File .\gdi.ps1 + \ No newline at end of file diff --git a/ActiveFax/GDI/gdi.ps1 b/ActiveFax/GDI/gdi.ps1 new file mode 100644 index 0000000..11e03c8 --- /dev/null +++ b/ActiveFax/GDI/gdi.ps1 @@ -0,0 +1,33 @@ +# Count GDI Handles for all Processes and send Mail to me when exceeding 6000 +# needed with ActFax for Windows Graphics Conversion Problems after March 2021 Updates +# +# v1.0 - 20.03.2021 - Initial Release + +# Get Ressource DLL +$sig = @' +[DllImport("User32.dll")] +public static extern int GetGuiResources(IntPtr hProcess, int uiFlags); +'@ +Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32 + +# Loop thru Processes +$processes = [System.Diagnostics.Process]::GetProcesses() +[int]$gdiHandleCount = 0 +ForEach ($p in $processes) +{ + try{ + $gdiHandles = [Win32.NativeMethods]::GetGuiResources($p.Handle, 0) +# Cout a Sum of GDI Handles over all Processes + $gdiHandleCount += $gdiHandles + } + catch { + } +} + +# Check total Number of Handles. There are max 9999 Handles on a Windows Server, so it is a good +# idea to send an alert when reaching 6000 +If ($gdiHandleCount -gt 6000) { +# When total GDI Objects greater 6000 send Mail to me with Number of Handles + Send-MailMessage -to "RECIPIENT@DOMAIN.COM" -from "SERVERNAME " -SmtpServer "SMTP.SERVER.NAME" -Subject "ALERT from FaxServer" -body $gdiHandleCount.ToString() + } + \ No newline at end of file