using LoginPI.Engine.ScriptBase; using System; public class activation_Office365Desktop : ScriptBase { void Execute() { /* -Disclaimer: This workload is provided as-is and might need further configuration and customization to work successfully in each unique environment. For further Professional Services-based customization please consult with the Login VSI Support and Services team. Please refer to the Help Center section "Application Customization" for further self-help information regarding workload crafting and implementation. -Run the workload against the "target" using Script Editor to ensure it will work before uploading it and testing with it -Go through the workload to understand what it's doing. Comment out any unneeded app tests (code blocks) or add on any needed functional testing -Workload version and changelist: --V1.0 | original -Leave Application running compatibility: false Workload developed with: -Login PI ScriptingToolSet ver. 3.5.9 -winword 365 Desktop version (reskinned 2019) ver. 1907 -Windows 10 x64 Pro winver 1903 18362.356 This script will: -Close out of Office desktop applications to prepare for activation -Open winword -Wait for the Activation flow window to appear -Progress through the flow and enter the defined account information -Wait for activation to complete and close out of the Office applications Please update the following variables: */ int TimeoutSeconds = 30; // Define here how many seconds to wait for functions to timeout; example: 30 -- for example, if winword doesn't launch in the timeout period int WaitSeconds = 5; // Define here how many seconds to wait in between functions; example: 5. This will allow for the target application's UI to catch up int CharactersPerMinuteType = 180; // Define how many characters per minute the typing function will type; example; 180 string DomainName = "@contoso.com"; // Define here the name of the test account's domain; example: "@contoso.com" -- this will be typed string WinwordLandingPageTitle = "*Document1*"; // Define here the name of the winword landing page; example: "*Document1*" int WaitSecondsActivation = 30; // Define here how many seconds to wait for the activation server communication to finalize; example: 30 // Making sure Office not running in the first place ShellExecute("cmd /c taskkill /f /im winword.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im excel.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im lync.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im powerpnt.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im outlook.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im microsoft.aad*",waitForProcessEnd:true,timeout:TimeoutSeconds); Wait(WaitSeconds); // Starting winword.exe and waiting for the initial landing page title to appear START(mainWindowTitle:WinwordLandingPageTitle,timeout:TimeoutSeconds); // Locating the Office activation window; interacting with it if it ends up existings var ActivationPrompt = FindWindow(title : "Sign in to set up Office",timeout:TimeoutSeconds,continueOnError:true); if (ActivationPrompt != null) { ActivationPrompt.Focus(); // Bringing activation prompt into focus var SignInButton = ActivationPrompt.FindControl(className : "Button:NetUISimpleButton", title :"Sign in",timeout:TimeoutSeconds); // Finding the sign-in button and clicking it Wait(WaitSeconds); SignInButton.Click(); // Waiting for user account/email address field to show, then typing the account name var UsernameField = MainWindow.FindControl(className : "Edit", title : "Email address",timeout:TimeoutSeconds); Wait(WaitSeconds); UsernameField.Click(); Wait(WaitSeconds); Type(Environment.UserName,cpm:CharactersPerMinuteType); Wait(WaitSeconds); Type(DomainName,cpm:CharactersPerMinuteType); Wait(WaitSeconds); var NextActivationButton = MainWindow.FindControl(className : "Button", title : "Next",timeout:TimeoutSeconds); // Clicking on the Next button to progress in the flow, which will communicate with activation servers NextActivationButton.Click(); Wait(WaitSecondsActivation); // This will wait for the defined time for Office to activate } // The following will close out of winword and Office applications again STOP(); ShellExecute("cmd /c taskkill /f /im winword.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im excel.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im lync.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im powerpnt.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im outlook.ex*",waitForProcessEnd:true,timeout:TimeoutSeconds); ShellExecute("cmd /c taskkill /f /im microsoft.aad*",waitForProcessEnd:true,timeout:TimeoutSeconds); } }