# Define the window title $windowTitle = 'worldserver' # Infinite loop to run the script every 15 minutes while ($true) { try { # Activate the window by searching for its title Add-Type @" using System; using System.Runtime.InteropServices; public class User32 { [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow(IntPtr hWnd); } "@ $windowHandle = [User32]::FindWindow([NullString]::Value, $windowTitle) if ($windowHandle -ne [IntPtr]::Zero) { [User32]::SetForegroundWindow($windowHandle) Start-Sleep -Seconds 1 # Wait for the window to activate # Send the command to the command-line interface using SendKeys Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.SendKeys]::SendWait('lfg clean') [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") } else { Write-Host "Window not found: $windowTitle" } } catch { Write-Host "Error: $_" } # Wait for 15 minutes before running the script again Start-Sleep -Seconds (15 * 60) }