Я новичок в С#. Я ищу решение для этого (приложение для проверки можно загрузить с http://download.eset.com/special/ESETLogCollector.exe
КОД:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
using System.Windows.Automation;
namespace LogCollector
{
class Program
{
static void Main(string[] args)
{
ProcessStartInfo proc = new ProcessStartInfo();
proc.UseShellExecute = true;
proc.WorkingDirectory = Environment.CurrentDirectory;
proc.FileName = "C:\\robot\\ESETLogCollector.exe";
proc.Verb = "runas";
Process.Start(proc);
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Ahoj");
AutomationElement desktop = AutomationElement.RootElement;
Condition cond = new PropertyCondition(AutomationElement.NameProperty, "ESET Log Collector");
AutomationElement elc = desktop.FindFirst(TreeScope.Children, cond);
Console.WriteLine(elc.Current.Name);
String save_path = "";
Condition cond1 = new PropertyCondition(AutomationElement.AutomationIdProperty, "1005");
try
{
AutomationElement save_as = elc.FindFirst(TreeScope.Subtree, cond1);
Console.WriteLine(save_as.Current.AutomationId);
save_path = save_as.Current.Name;
}
catch (System.Exception e)
{
Console.WriteLine("EX: {0}", e.Message);
}
if (System.IO.File.Exists(save_path))
{
System.IO.File.Delete(save_path);
Console.WriteLine(save_path);
}
Condition cond2 = new PropertyCondition(AutomationElement.AutomationIdProperty, "1002");
AutomationElement collect = elc.FindFirst(TreeScope.Children, cond2);
Console.WriteLine(collect.Current.Name);
try
{
Object outObject;
collect.TryGetCurrentPattern(InvokePattern.Pattern, out outObject);
InvokePattern pattern = outObject as InvokePattern;
pattern.Invoke();
}
catch (System.Exception e)
{
Console.WriteLine("EX: {0}", e.Message);
}
Console.ReadKey();
}
}
}
Все, что я до сих пор получаю, если я хочу вызвать buttonclick: операция недействительна из-за текущей статистики объекта
Я действительно не знаю, что здесь происходит. Может ли кто-нибудь помочь мне в этом?
Ty
Операция, вероятно, терпит неудачу, потому что вы не запускаете приложение автоматизации как администратор, в то время как ESET Log Collector запускается с повышенными разрешениями.
Обзор безопасности автоматизации пользовательского интерфейса описывает модель безопасности и способы взаимодействия с процессами, которые работают на более высоком уровне привилегий (т.е. Вам требуется подписанное приложение с файлом манифеста, который включает специальный атрибут).