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