Initial Release of GDI Check

This commit is contained in:
2021-03-20 07:22:45 +01:00
parent c07db4a130
commit 425430a3dc
2 changed files with 41 additions and 0 deletions

33
ActiveFax/GDI/gdi.ps1 Normal file
View File

@@ -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 <SERVER@DOMAIN.COM>" -SmtpServer "SMTP.SERVER.NAME" -Subject "ALERT from FaxServer" -body $gdiHandleCount.ToString()
}