Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was suggested to use <a href="http://msdn.microsoft.com/en-us/library/ms747327.aspx" rel="nofollow">UI Automation</a>, and here's what I've conjured up so far:</p> <pre class="lang-cs prettyprint-override"><code>using System.Diagnostics; using System.Threading; using System.Windows.Automation; class Program { static void Main(string[] args) { var processStartInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TailoredDeploy.exe", "AcquireDeveloperLicense"); var process = Process.Start(processStartInfo); process.WaitForInputIdle(); Thread.Sleep(1000); var agreementWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, process.Id)); var iAgreeButton = agreementWindow.FindAll(TreeScope.Children, Condition.TrueCondition)[0] .FindAll(TreeScope.Children, Condition.TrueCondition)[2]; var buttonPattern = iAgreeButton.GetCurrentPattern(AutomationPattern.LookupById(InvokePattern.Pattern.Id)) as InvokePattern; buttonPattern.Invoke(); Thread.Sleep(10000); var processes = Process.GetProcessesByName("dllhost"); var credentialsWindows = AutomationElement.RootElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, processes[0].Id)); if (credentialsWindows[0].Current.Name == "Developer License") { var credentialsPane = credentialsWindows[0].FindAll(TreeScope.Children, Condition.TrueCondition)[0] .FindAll(TreeScope.Children, Condition.TrueCondition)[0] .FindAll(TreeScope.Children, Condition.TrueCondition)[0] .FindAll(TreeScope.Children, Condition.TrueCondition)[0] .FindAll(TreeScope.Children, Condition.TrueCondition); var usernameTextBox = credentialsPane[3].GetCurrentPattern(AutomationPattern.LookupById(ValuePattern.Pattern.Id)) as ValuePattern; usernameTextBox.SetValue("username@outlook.com"); var passwordTextBox = credentialsPane[5].GetCurrentPattern(AutomationPattern.LookupById(ValuePattern.Pattern.Id)) as ValuePattern; passwordTextBox.SetValue("password"); var loginButton = credentialsPane[8].GetCurrentPattern(AutomationPattern.LookupById(InvokePattern.Pattern.Id)) as InvokePattern; loginButton.Invoke(); Thread.Sleep(10000); var finishUpProcesses = Process.GetProcessesByName("TailoredDeploy"); var finishWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, finishUpProcesses[0].Id)); var lastItems = finishWindow.FindAll(TreeScope.Children, Condition.TrueCondition)[0] .FindAll(TreeScope.Children, Condition.TrueCondition); var closeButton = lastItems[3].GetCurrentPattern(AutomationPattern.LookupById(InvokePattern.Pattern.Id)) as InvokePattern; closeButton.Invoke(); } } } </code></pre> <p>To use this, a <code>app.manifest</code> is required to run in elevated mode:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;assemblyIdentity version="1.0.0.0" name="MyApplication.app"/&gt; &lt;trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"&gt; &lt;security&gt; &lt;requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"&gt; &lt;requestedExecutionLevel level="requireAdministrator" uiAccess="false" /&gt; &lt;/requestedPrivileges&gt; &lt;/security&gt; &lt;/trustInfo&gt; &lt;compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"&gt; &lt;application&gt; &lt;/application&gt; &lt;/compatibility&gt; &lt;/asmv1:assembly&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload