Tag: 自动化

从C#调用PowerShell

我正在使用System.Management.Automation DLL,它允许我在我的C#应用​​程序中调用PowerShell,如下所示: PowerShell.Create().AddScript(“Get-Process”).Invoke(); 我想要做的是调用PowerShell但提供输入列表。 例如,在: 1, 2, 3 | ForEach-Object { $_ * 2 } 我在调用时试图提供左侧1, 2, 3 : // powershell is a PowerShell Object powershell.Invoke(new [] { 1, 2, 3 }); 但是这不起作用。 我想出的解决方法是使用ForEach-Object ,然后将数组作为InputObject传递,并使用{ $_ }作为Process : // create powershell object var powershell = PowerShell.Create(); // input array 1, 2, 3 Command inputCmd = […]

在C#中创建COM自动化服务器

我目前有一个用C#编写的.NET类库,它通过COM将其function暴露给C ++程序(pre -.NET)。 我们现在想要将库移出进程以释放主应用程序中的地址空间(它是一个图像处理应用程序,大图像占用了地址空间)。 我记得在我的VB6时代,人们可以创建一个“OLE自动化服务器”。 操作系统会在创建/销毁对象时自动启动和停止服务器.exe。 这看起来非常适合我们:据我所知,除了用CLSCTX_LOCAL_SERVER而不是CLSCTX_INPROC_SERVER调用CoCreateInstance之外,客户端不会发生任何变化。 我如何在C#中创建这样的进程外服务器? 要么网上没有关于它的信息,要么我的术语已经过时/过时了!

如何从任何窗口获取选定的文本(使用UI自动化) – C#

我有一个小托盘应用程序,它注册一个系统范围的热键。 当用户在任何应用程序中的任何位置选择文本并按下此热键时,我希望能够捕获所选文本。 我目前正在使用AutomationElements这样做: //Using FocusedElement (since the focused element should be the control with the selected text?) AutomationElement ae = AutomationElement.FocusedElement; AutomationElement txtElement = ae.FindFirst(TreeScope.Subtree,Condition.TrueCondition); if(txtElement == null) return; TextPattern tp; try { tp = txtElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; } catch(Exception ex) { return; } TextPatternRange[] trs; if (tp.SupportedTextSelection == SupportedTextSelection.None) { return; } else { […]

UI自动化“选定文本”

任何人都知道如何使用UI Automation和.Net从其他应用程序中获取所选文本? http://msdn.microsoft.com/en-us/library/ms745158.aspx