33 lines
1.2 KiB
PowerShell
33 lines
1.2 KiB
PowerShell
|
|
# 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()
|
||
|
|
}
|
||
|
|
|