Power Automate Desktop †更新日2024-11-08 (金) 11:24:35
作成日:2024年11月7日
Power Automate DesktopはWindowsのソフトの起動、メニュー操作、テキストボックスへの入力などを順に自動で行うシーケンサーみたいなもの。 インストール †
既に入っているので、power automateでアプリを検索する
以下からPower Automate インストーラーをダウンロードしてインストールする。 起動 †起動するとMSアカウントでログインを求められるので、ログインする。 起動すると以下のような画面にになる 自分のフローに移動して、「新しいフロー」を選択する。 フローを作成する画面で、フロー名を入力して作成ボタンを押す。 以下の作成画面が開く &ref(): File not found: "起動4.png" at page "Windows_Router Memo/Power Automate Desktop"; 左ペインのアクションから中央のペインのMainのペインにドラックして並べていく サンプル作成 †アクション内容 †以下の手順でアプリケーションを起動させ、起動画面を表示させる。
アクション内容入力 †
メニューバーから選択をサーバアドレスが表示している個所(画像)をクリックするように変更 †
保存画像の削除 †ショートカット作成 †
# Power Automate for desktopのフローを実行するPowerShellスクリプト # @param [string] $flowName 実行するフロー名 # @param [bool] $flgExit PAD終了フラグ # # 動作確認:バージョン 2.40.157.24023 (インストーラー版) # Param( [bool]$flgExit = $false ) #Power Automate for desktop起動 Start-Process -FilePath "ms-powerautomate://" #UI Automation Add-Type -AssemblyName "UIAutomationClient" Add-Type -AssemblyName "UIAutomationTypes" $uiAuto = [System.Windows.Automation.AutomationElement] $pcdn = [System.Windows.Automation.PropertyCondition] $acdn = [System.Windows.Automation.AndCondition] $tree = [System.Windows.Automation.TreeScope] $iptn = [System.Windows.Automation.InvokePattern]::Pattern $wptn = [System.Windows.Automation.WindowPattern]::Pattern $icptn = [System.Windows.Automation.ItemContainerPattern]::Pattern $siptn = [System.Windows.Automation.ScrollItemPattern]::Pattern $selptn = [System.Windows.Automation.SelectionItemPattern]::Pattern $root = $uiAuto::RootElement #Power Automate for desktopウィンドウ取得 $cndPadWindowId = New-Object $pcdn($uiAuto::AutomationIdProperty, "ConsoleMainWindow") $cndPadWindowClassName = New-Object $pcdn($uiAuto::ClassNameProperty, "WinAutomationWindow") $cndPadWindow = New-Object $acdn($cndPadWindowId, $cndPadWindowClassName) do{ Start-Sleep -m 200 $elmPadWindow = $root.FindFirst($tree::Children, $cndPadWindow) }while($elmPadWindow -eq $null) #タブ取得 $cndTab = New-Object $pcdn($uiAuto::AutomationIdProperty, "ProcessesTabControl") $elmTab = $elmPadWindow.FindFirst($tree::Subtree, $cndTab) #タブ項目取得・選択 if($elmTab -ne $null){ $cndTabItem = New-Object $pcdn($uiAuto::AutomationIdProperty, "MyFlowsTab") $elmTabItem = $elmTab.FindFirst($tree::Children, $cndTabItem) if($elmTabItem -ne $null){ $selTabItem = $elmTabItem.GetCurrentPattern($selptn) $selTabItem.Select() } } #データグリッド取得 if($elmPadWindow -ne $null){ $cndDataGrid = New-Object $pcdn($uiAuto::AutomationIdProperty, "MyFlowsListGrid") $elmDataGrid = $elmPadWindow.FindFirst($tree::Subtree, $cndDataGrid) } #データ項目取得・選択 if($elmDataGrid -ne $null){ $icDataGrid = $elmDataGrid.GetCurrentPattern($icptn) $elmDataItem = $icDataGrid.FindItemByProperty($null, $uiAuto::NameProperty, "KpacsStart") #←ここに名前を入れる。ただし必ず半角 if($elmDataItem -ne $null){ $siDataItem = $elmDataItem.GetCurrentPattern($siptn) $siDataItem.ScrollIntoView() $selDataItem = $elmDataItem.GetCurrentPattern($selptn) $selDataItem.Select() } } #実行ボタン取得・押下 if($elmDataItem -ne $null){ $cndStartButton = New-Object $pcdn($uiAuto::AutomationIdProperty, "StartFlowButton") $elmStartButton = $elmDataItem.FindFirst($tree::Subtree, $cndStartButton) if($elmStartButton -ne $null){ $ivkStartButton = $elmStartButton.GetCurrentPattern($iptn) $ivkStartButton.Invoke() } } if($flgExit){ #フロー終了待ち if($elmStartButton -ne $null){ do{ Start-Sleep -m 800 }while($elmStartButton.GetCurrentPropertyValue($uiAuto::IsEnabledProperty) -eq $false) } #Power Automate for desktop終了 $winPadWindow = $elmPadWindow.GetCurrentPattern($wptn) $winPadWindow.Close() }
さらに、以下のようなバッチを作成してそのショートカットを作成する
powershell -ExecutionPolicy Bypass -File "kidou.ps1" 参考(ショートカット) † |