本帖最后由 小白龙 于 2025-3-25 12:02 编辑
下面的C#代码是gpt从python代码转换过来的, 可以在老版(5.X或6.X)的剪映导航窗口自动打开指定的草稿,
但是有个问题, 有时不知道为啥对象e就报错了, 然后重启剪映导航窗口就可以了, 后面我又用gpt转成powershell, 但是死活就是无法执行, 总是报错, 求路过精通C#和powershell的大佬指导, 多谢 | using FlaUI.UIA3; | | using FlaUI.Core.Conditions; | | | | var apps = Process.GetProcessesByName("JianyingPro") | | .Where(p => p.MainWindowHandle != IntPtr.Zero); | | | | using var automation = new UIA3Automation(); | | IntPtr mainWindowHandle = apps.First().MainWindowHandle; | | var mainWindow = automation.FromHandle((nint)mainWindowHandle); | | | | var condition = new PropertyCondition(automation.PropertyLibrary.Element.FullDescription, "HomePageDraftTitle:3月22日"); | | var e = mainWindow.FindFirstDescendant(condition); | | e.Parent.Click();COPY |
Powershell代码: | Add-Type -Path ".\FlaUI.UIA3.dll" | | | | try { | | $apps = Get-Process "JianyingPro" | ? { $_.MainWindowHandle -ne 0 } | | $automation = New-Object "FlaUI.UIA3.UIA3Automation" | | $mainWindowHandle = $apps[0].MainWindowHandle | | $mainWindow = $automation.FromHandle($mainWindowHandle); | | | | $condition = New-Object "PropertyCondition" ` | | @($automation.PropertyLibrary.Element.FullDescription, "HomePageDraftTitle:3月22日") | | | | $e = $mainWindow.FindFirstDescendant($condition) | | | | $e.Parent.Click() | | } | | catch { | | Write-Error "发生错误: $_" | | } | | finally { | | | | if ($automation) { $automation.Dispose() } | | }COPY |
|