AutoClose Windows Manager

The “AutoClose Windows Manager” is an advanced PowerShell script designed to optimize efficiency and resource usage in Windows-based work environments, especially if you work with remote desktop servers. It continuously monitors mouse cursor activity and initiates the automatic closure of all open application windows after 10 minutes of inactivity. This feature significantly contributes to the conservation of system resources by ensuring that unused applications do not unnecessarily occupy system capacities.

A major advantage of this script is its seamless integration into corporate environments through connection to Microsoft Active Directory. It can be stored as a Group Policy Object (GPO), ensuring widespread and automated distribution across all associated end devices. This centralized implementation strategy significantly eases the management and enforcement of resource conservation policies, without the need for individual configurations on each device.

As an extension of the core script, there is the option to integrate detailed analyses of software usage. This feature allows administrators to gain insights into application activities and frequencies, providing a well-informed basis for optimizing software licenses and further customizing the IT infrastructure. These additional data can offer valuable insights to further enhance the efficiency and effectiveness of IT resources in an organization.

Functional principle:

How does the script work?

PowerShell script:

Add-Type @” using System; using System.Runtime.InteropServices; public class Mouse { [DllImport(“user32.dll”)] public static extern bool GetCursorPos(out POINT lpPoint); [StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; } public static POINT GetCursorPosition() { POINT lpPoint; GetCursorPos(out lpPoint); return lpPoint; } } “@ $lastPosition = [Mouse]::GetCursorPosition() $lastMoveTime = Get-Date while ($true) { Start-Sleep -Seconds 10 # Überprüft alle 10 Sekunden die Position $position = [Mouse]::GetCursorPosition() if ($position.X -eq $lastPosition.X -and $position.Y -eq $lastPosition.Y) { # Überprüft, ob 10 Minuten vergangen sind, ohne dass sich die Maus bewegt hat if (((Get-Date) – $lastMoveTime).TotalMinutes -ge 10) { # Schließt alle Fenster Get-Process | Where-Object { $_.MainWindowTitle -ne “” } | Stop-Process $lastMoveTime = Get-Date # Zeitpunkt der letzten Aktion aktualisieren } } else { $lastPosition = $position # Aktualisiert die letzte bekannte Position $lastMoveTime = Get-Date # Zeitpunkt der letzten Bewegung aktualisieren } }