gpt4 book ai didi

c# - pattern.Invoke() 异常 : Operation is not valid due to the current state of the object

转载 作者:太空宇宙 更新时间:2023-11-03 19:06:34 25 4
gpt4 key购买 nike

我是 C# 的新手。我正在寻找解决方案(可以从 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,我仍然得到的是:由于对象的当前状态,操作无效

我真的不知道这里发生了什么。有人可以帮我解决这个问题吗?

最佳答案

操作可能失败,因为您没有以管理员身份运行自动化应用程序,而 ESET Log Collector 已以提升的权限运行。

UI Automation Security Overview描述了安全模型以及如何与以更高权限级别运行的进程进行通信(即,您需要一个带有包含特殊属性的 list 文件的签名应用程序)。

关于c# - pattern.Invoke() 异常 : Operation is not valid due to the current state of the object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26258299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com