Initial Release of GDI Check
This commit is contained in:
8
ActiveFax/GDI/gdi.cmd
Normal file
8
ActiveFax/GDI/gdi.cmd
Normal file
@@ -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
|
||||||
|
|
||||||
33
ActiveFax/GDI/gdi.ps1
Normal file
33
ActiveFax/GDI/gdi.ps1
Normal 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()
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user