// TARGET:winword.exe "%TEMP%\\LoginEnterprise\\loginvsi.docx" // START_IN: ///////////// // Word Start // Workload: Activation-less Office Workloads // Version: 1.0.0 ///////////// using LoginPI.Engine.ScriptBase; using System; using System.IO; public class Word_Start_Office_Activation_less : ScriptBase { // ===================================================== // Configurable Variables // ===================================================== int globalWaitInSeconds = 3; // Wait time between actions int waitMessageboxInSeconds = 2; // Duration for onscreen wait messages int activationDialogRetryCount = 2; // How many times to attempt dismissing activation dialogs // ===================================================== // Execute Method // ===================================================== private void Execute() { Log("Preparing Word activation-less workload."); DownloadWordDocument(); Wait(waitMessageboxInSeconds, showOnScreen: true, onScreenText: "Starting Word"); Log("Starting Word."); START( mainWindowTitle: "*loginvsi*Word*", mainWindowClass: "Win32 Window:OpusApp", processName: "WINWORD", timeout: 60, continueOnError: true ); Wait(globalWaitInSeconds); SkipActivationDialogs(); MainWindow.Maximize(); MainWindow.Focus(); Wait(globalWaitInSeconds); Log("Word is now ready."); } // ===================================================== // Helper: Download Word document if missing // ===================================================== private void DownloadWordDocument() { Log("Ensuring Word document is present."); string tempDir = Path.Combine(GetEnvironmentVariable("TEMP"), "LoginEnterprise"); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); Log("Created directory: " + tempDir); } string docxFile = Path.Combine(tempDir, "loginvsi.docx"); if (!File.Exists(docxFile)) { Wait(waitMessageboxInSeconds, showOnScreen: true, onScreenText: "Downloading Word document"); CopyFile(KnownFiles.WordDocument, docxFile, continueOnError: true, overwrite: false); Log("Downloaded document: " + docxFile); } else { Log("Document already exists: " + docxFile); } } // ===================================================== // Helper: Dismiss Activation Dialogs (NUIDialog) // ===================================================== private void SkipActivationDialogs() { for (int i = 0; i < activationDialogRetryCount; i++) { var dialog = FindWindow( className: "Win32 Window:NUIDialog", processName: "WINWORD", continueOnError: true, timeout: 3 ); if (dialog == null) break; Wait(globalWaitInSeconds, showOnScreen: true, onScreenText: "Closing activation dialog"); dialog.Close(); Log("Dismissed an activation dialog."); } } }