UIAutomation command bat

References:

System;

System.Data;

System.Data.DataSetExtensions;

System.Windows.Forms;

System.Xml;

System.Xml.Linq;

UIAutomationClient;

UIAutomationClientsideProviders;

UIAutomationProvider;

UIAutomationProvider;

UIAutomationTypes;

WindowsBase;

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Automation;

using System.Runtime.InteropServices;

using System.Security.Permissions;

namespace ConsoleApplication2

{

[PermissionSet(SecurityAction.Demand, Name = "FullTrust" )]

[ComVisibleAttribute(true )]

class Program
{

#region Variations

const int MOUSEEVENTF_MOVE = 0x0001;

const int MOUSEEVENTF_LEFTDOWN = 0x0002;

const int MOUSEEVENTF_LEFTUP = 0x0004;

const int MOUSEEVENTF_RIGHTDOWN = 0x0008;

const int MOUSEEVENTF_RIGHTUP = 0x0010;

const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;

const int MOUSEEVENTF_MIDDLEUP = 0x0040;
#endregion

#region SetCursoPos
[DllImport("user32.dll" )]
extern static int SetCursorPos(int incrementX, int incrementY);
#endregion

#region Mouse click event

/// <summary>
/// Mouse click event
/// </summary>
/// <param name="mouseEventFlag">MouseEventFlag </param>
/// <param name="incrementX">X coordinate </param>
/// <param name="incrementY">Y coordinate </param>
/// <param name="data"></param>
/// <param name="extraInfo"></param>

[DllImport("user32.dll" )]

extern static void mouse_event(int mouseEventFlag, int incrementX, int incrementY, uint data, UIntPtr extraInfo);

#endregion

#region Click AutomationElement
/// <summary>
///
/// </summary>
/// <param name="ae"></param>

public static void LeftClick(AutomationElement ae)
{

System.Windows.Rect rect = ae.Current.BoundingRectangle;

int IncrementX = (int )(rect.Left + rect.Width / 2);
int IncrementY = (int )(rect.Top + rect.Height / 2);

//Make the cursor position to the element.
SetCursorPos(IncrementX, IncrementY);

//Make the left mouse down and up.

mouse_event(MOUSEEVENTF_LEFTDOWN, IncrementX, IncrementY, 0, UIntPtr .Zero);

mouse_event(MOUSEEVENTF_LEFTUP, IncrementX, IncrementY, 0, UIntPtr .Zero);

}

public static void RightClick(AutomationElement Element)
{

System.Windows.Rect rect = Element.Current.BoundingRectangle;
int IncrementX = (int )(rect.Left + rect.Width / 2);
int IncrementY = (int )(rect.Top + rect.Height / 2);

//Make the cursor position to the element.

SetCursorPos(IncrementX, IncrementY);

//Make the left mouse down and up.

mouse_event(MOUSEEVENTF_RIGHTDOWN, IncrementX, IncrementY, 0, UIntPtr.Zero);

mouse_event(MOUSEEVENTF_RIGHTUP, IncrementX, IncrementY, 0, UIntPtr .Zero);

}

#endregion

#region DelaySeconds

/// <summary>
/// Delay Seconds
/// </summary>
/// <param name="num"></param>

private static void DelaySeconds(int num)
{

System.Threading.Thread .Sleep(1000 * num);

}

#endregion

static void Main(string [] args)
{
string computerName = System.Configuration.ConfigurationSettings.AppSettings["ComputerName" ].ToUpper();
computerName = computerName == "" ? System.Net.Dns.GetHostEntry("localhost").HostName.Remove(System.Net.Dns.GetHostEntry("localhost").HostName.IndexOf('.' )).ToUpper() : computerName;
string process1 = System.Configuration.ConfigurationSettings.AppSettings["Process1" ];
for (int i = 1; i < 100; i++)
{
string processi = System.Configuration.ConfigurationSettings.AppSettings["Process" + i.ToString()];
if (processi == null )
{
Console .WriteLine(i);
break ;
}
string[] processiArr = processi.Split('$' );
System.Diagnostics.Process process1 = System.Diagnostics.Process.Start(@"" + processiArr[0]);
process1.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle .Normal;
process1.WaitForInputIdle(1000);
Console.WriteLine(processi);
}
string step1 = System.Configuration.ConfigurationSettings.AppSettings["Step1"];
AutomationElement[] UIElement = new AutomationElement [100];
for (int i = 1; i < 100; i++)
{
string stepi = System.Configuration.ConfigurationSettings.AppSettings["Step" + i.ToString()];
if (stepi == null )
{
Console.WriteLine(i);
break;
}
else
{
stepi = stepi.Replace("%ComputerName%" , computerName);
string[] stepiArr = stepi.Split('$');
if (stepiArr[0].ToUpper() == "Edit".ToUpper())
{
System.Windows.Forms.SendKeys.SendWait(stepiArr[2]);
Console.WriteLine("Edit: " + stepiArr[2]);
}
else if (stepiArr[0].ToUpper() == "Delay".ToUpper())
{
DelaySeconds(Convert .ToInt32(stepiArr[2]));
Console.WriteLine("DelaySeconds: " +stepiArr[2]);
}
else
{
if (stepiArr.Length > 5)
{
UIElement[i] = FindAutomationElement(stepiArr[1] == "Step0" ? AutomationElement.RootElement : UIElement[Convert.ToInt32(stepiArr[1].Substring(4, stepiArr[1].Length - 4))], TreeScope.Descendants,
AutomationElement.NameProperty, stepiArr[2],
AutomationElement.AutomationIdProperty, stepiArr[3],
AutomationElement.ControlTypeProperty, StringToControlType(stepiArr[4]),
AutomationElement.ClassNameProperty, stepiArr[5]);
}
else
{
UIElement[i] = FindAutomationElement(stepiArr[1] == "Step0" ? AutomationElement.RootElement : UIElement[Convert.ToInt32(stepiArr[1].Substring(4, stepiArr[1].Length - 4))], TreeScope .Descendants,
AutomationElement.NameProperty, stepiArr[2],
AutomationElement.AutomationIdProperty, stepiArr[3],
AutomationElement.ControlTypeProperty, StringToControlType(stepiArr[4]));
}

if (UIElement == null )
{
Console.WriteLine("UIElement is null" );
}
else
{
Console.WriteLine("UIElement " + stepiArr[2] + " found" );
if (stepiArr[0].ToUpper() == "LeftClick".ToUpper())
{
LeftClick(UIElement[i]);
Console.WriteLine("LeftClick " + stepiArr[2]);
}
else if (stepiArr[0].ToUpper() == "RightClick".ToUpper())
{
RightClick(UIElement[i]);
Console.WriteLine("RightClick " + stepiArr[2]);
}
}
}
}
Console.WriteLine(stepi);
}
Console.Read();
}

public static object StringToControlType(string str)
{
object controlType = null ;

if (str == "Window") controlType = ControlType.Window;
else if (str == "MenuItem") controlType = ControlType.MenuItem;
else if (str == "Document") controlType = ControlType.Document;
else if (str == "TreeItem") controlType = ControlType.TreeItem;
else if (str == "Menu" ) controlType = ControlType.Menu;
else if (str == "MenuItem") controlType = ControlType.MenuItem;
else if (str == "Document") controlType = ControlType.Document;
else if (str == "Document") controlType = ControlType.Document;
else if (str == "Document") controlType = ControlType.Document;
return controlType;
}

public static AutomationElement FindAutomationElement(AutomationElement automationElement, TreeScope treeScope,
AutomationProperty automationProperty1, object value1,
AutomationProperty automationProperty2, object value2,
AutomationProperty automationProperty3, object value3)
{
return automationElement.FindFirst
(

treeScope,
new AndCondition
(
new PropertyCondition(automationProperty1, value1),
new PropertyCondition(automationProperty2, value2),
new PropertyCondition(automationProperty3, value3)
)

);

}

public static AutomationElement FindAutomationElement(AutomationElement automationElement, TreeScope
treeScope,
AutomationProperty automationProperty1, object value1,
AutomationProperty automationProperty2, object value2,
AutomationProperty automationProperty3, object value3,
AutomationProperty automationProperty4, object value4)
{
return automationElement.FindFirst
(
treeScope,
new AndCondition
(
new PropertyCondition (automationProperty1, value1),
new PropertyCondition (automationProperty2, value2),
new PropertyCondition (automationProperty3, value3),
new PropertyCondition (automationProperty4, value4)
)
);

}

}

}

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ComputerName" value=""/>
<add key="Process1" value="C:/aaa.exe"/>

<!--
value=action$StepN$NameProperty$AutomationIdProperty$ControlTypeProperty
value=action$StepN$NameProperty$AutomationIdProperty$ControlTypeProperty$ClassNameProperty

value=Edit$StepN$EditValue

value=Delay$StepN$seconds

1.action:LeftClick;RightClick;Edit;Delay;

StepN:

NameProperty:

AutomationIdProperty:

ControlTypeProperty:

2.EditValue:/when action is Edit;

"%{N}" is ALT+N;

"^s" is Ctrl+S;

"{Enter}" is press Enter key;

"%{F4}" is Alt+F4;

-->

<add key="Step1" value="LeftClick$Step0$aaa Server Manager$$Window"/>
<add key="Step2" value="LeftClick$Step1$Management Server$$TreeItem"/>
<add key="Step3" value="Edit$Step1${RIGHT}" />
<add key="Step4" value="LeftClick$Step1$Action Servers$$TreeItem"/>
<add key="Step5" value="Edit$Step1${RIGHT}"/>
<add key="Step6" value="Delay$Step0$2" />
<add key="Step7" value="RightClick$Step1$%ComputerName%$$TreeItem"/>
<add key="Step8" value="Delay$Step0$2" />
<add key="Step9" value="RightClick$Step0$Menu$$Menu$#32768"/>
<add key="Step10" value="LeftClick$Step9$Uninstall Action Server$Item 44101$MenuItem"/>
</appSettings>
</configuration>

时间: 2024-10-28 23:35:46

UIAutomation command bat的相关文章

运行cmd直接进入指定目录下的命令_DOS/BAT

新建一个.bat批处理文件,文件里命令: 复制代码 代码如下: @ECHO OFF cmd /k cd /d c:\data 然后运行该批处理文件cmd就可进入指定的 "c:\data"目录下. 参考: cmd /k的含义 Microsoft DOS cmd and command Bat命令学习 (实用)

BAT CMD批处理文件脚本总结

1.综述 (1).".bat": 这是微软的第一个批处理文件的后缀名,在几乎所有的 Windows 操作系统内都能运行. (2).".cmd": 是为Windows NT 设计的命令行脚本,为Cmd.exe shell 而设计的,对于COMMAND.COM不具有向后兼容性. (3).目前所知道的.cmd 和 .bat文件的区别是对ERRORLEVEL变量的改变:当 Command Extensions (命令行扩展)处于enabled状态时,哪怕是.cmd文件中一

BAT批处理一键生成APK包脚本分享

  这篇文章主要介绍了BAT批处理一键生成APK包脚本分享,本文脚本适用于cocos2dx+lua的项目,需要的朋友可以参考下 BAT批处理一键生成APK包脚本分享 将本bat放到cocos2dx目录下你的工程的project.android下(需修改变量). ASmaker 用来将Resources文件夹下的lua文件批量加密 算法参考我之前的rc4算法实现. 每次打包apk前 svn 最新的工程代码 和 cocos2dx引擎代码. ? 1 2 3 4 5 6 7 8 9 10 11 12 1

windows下直接点击startup.bat启动tomcat服务

  在XP上明明已经安装了JDK1.5并设置好了JAVA_HOME,可偏偏Tomcat在启动过程中找不到. 报错信息如下:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program;提示找不到java_home各jre_home路径,何解? 原因不知道了,下面来看解决办法

windows bat(批处理):IF详解

  windows bat(批处理)--IF详解 摘要:本文介绍了windows bat中IF语句的语法,包括3中基本形势和扩展IF语句 1. IF & IF not if 和 if not 有都有3中形势: IF [NOT] ERRORLEVEL number do command IF [NOT] string1==string2 do command IF [NOT] EXIST filename do command NOT 指定只有条件为 false 的情况下,Windows 才应该执

几个电脑优化清除垃圾bat命令

  一.清理垃圾 在Windows在安装和使用过程中都会产生相当多的垃圾文件,包括临时文件(如:*.tmp.*._mp)日志文件(*.log).临时帮助文件(*.gid).磁盘检查文件(*.chk).临时备份文件(如:*.old.*.bak)以及其他临时文件.特别是如果一段时间不清理IE的临时文件夹"Temporary Internet Files",其中的缓存文件有时会占用上百MB的磁盘空间.这些LJ文件不仅仅浪费了宝贵的磁盘空间,严重时还会使系统运行慢如蜗牛.这点相信你肯定忍受不了

bat执行java程序 good

  start.bat set MY_HOME=%~dp0  set JMS_BINDING_PATH=%MY_HOME%..\binds set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_08\ set path=%path%;%JAVA_HOME%bin; set CLASSPATH=.;%JAVA_HOME%lib\tools.jar;%JAVA_HOME%lib\dt.jar;%MY_HOME%..\bomc-sa-tdagent.jar;%MY_

选中文件夹设定为IIS站点主目录的批处理bat

原文:选中文件夹设定为IIS站点主目录的批处理bat 我使用的OS是winxp,安装的IIS版本为5.1,不支持多站点,下载的一些源代码想测试浏览一下就得设定虚拟目录,而且有些还必须设为站点根目录,每次改的时候就需要打开IIS然后默认站点,右键属性->主目录这样设定一番,天天这么重复设定就感觉麻烦的很了,于是就想如果能在源代码文件夹右键直接设定为IIS主目录多好啊,搜索了一下也没找到相关的小工具,就自己着手鼓捣一下吧,费了半天劲终于使用bat改写注册表整成了,正常运行该bat的requireme

批处理BAT(一)

批处理 全盘根目录下查找文件夹并删除(1) @echo off for %%a in (C D E F G H) DO ( cd\ if exist "%%a:\123\" rd /s /q "%%a:\123\" ) echo 命令成功完成 pause 说明:上面这段红色代码表示,在全盘根目录下查找文件夹"123",并且找到后,无论该文件夹内是否还有其他文件或文件夹都一并删除.此批处理命令不支持在子目录中查找文件夹"123"