// TARGET:winword.exe /e // START_IN: ///////////// // Word Close // Workload: Activation-less Office Workloads // Version: 1.0.0 ///////////// using LoginPI.Engine.ScriptBase; public class Word_Close_Office_Activation_less : ScriptBase { // ===================================================== // Configurable Variables // ===================================================== int globalWaitInSeconds = 3; // Wait time between actions int timeoutSeconds = 2; // Timeout for window searches // ===================================================== // Execute Method // ===================================================== private void Execute() { Log("Closing the LoginVSI Word document."); CloseWindow("WINWORD", "*loginvsi*"); } // ===================================================== // Helper: Close a single Word window matching titleMask // ===================================================== void CloseWindow(string processName, string titleMask) { var win = FindWindow( processName: processName, title: titleMask, timeout: timeoutSeconds, continueOnError: true ); if (win == null) { Log($"No window found matching '{titleMask}'."); return; } win.Focus(); win.Maximize(); Wait(globalWaitInSeconds); // Attempt to close via ESC then ALT+F4 win.Type("{ESC}", hideInLogging: false); Wait(globalWaitInSeconds); win.Type("{ALT+F4}", hideInLogging: false); Wait(globalWaitInSeconds); // If still open, dismiss any confirmation with ALT+N win = FindWindow( processName: processName, title: titleMask, timeout: timeoutSeconds, continueOnError: true ); if (win != null) { Log("Confirmation dialog detected, dismissing."); Wait(globalWaitInSeconds); win.Type("{ALT+N}", hideInLogging: false); Wait(globalWaitInSeconds); } Log("Word document closed."); } }