#author("2024-11-08T11:21:57+09:00","default:okada","okada")
#author("2024-11-08T11:24:35+09:00","default:okada","okada")
*Power Automate Desktop [#jf259e71]

RIGHT:更新日&lastmod();
RIGHT:作成日:2024年11月7日

Power Automate DesktopはWindowsのソフトの起動、メニュー操作、テキストボックスへの入力などを順に自動で行うシーケンサーみたいなもの。

**インストール [#aef24286]

-Windows11

既に入っているので、power automateでアプリを検索する

-Windows10

以下からPower Automate インストーラーをダウンロードしてインストールする。

--https://learn.microsoft.com/ja-jp/power-automate/desktop-flows/install


**起動 [#rf5b8b4a]

起動するとMSアカウントでログインを求められるので、ログインする。

起動すると以下のような画面にになる

&ref("./起動.png");

自分のフローに移動して、「新しいフロー」を選択する。

&ref("./起動2.png");

フローを作成する画面で、フロー名を入力して作成ボタンを押す。

&ref("./起動3.png");

以下の作成画面が開く

&ref("./起動4.png");

左ペインのアクションから中央のペインのMainのペインにドラックして並べていく

&ref("./起動5.png");

**サンプル作成 [#ifcdf024]

***アクション内容 [#m4d7c926]

以下の手順でアプリケーションを起動させ、起動画面を表示させる。

+目的のアプリケーションを起動
+PADのコンソールを終了
+所定の画面が表示するまで待機
+メニューバーから目的のメニュ−を選択(階層になっているため、1階層づつ選択個所を指定)
+所定の画面が表示するまで待機
+矢印キーを2つ押して、Enterキーを入力
+テキストフィールドにファーカスをあてる
+テキストフィールドに文字列を入力して、Enterキーを入力
+二つ目のテキストフィールドにファーカスをあて文字列を入力して、Enterキーを入力

***アクション内容入力 [#r0ec1d91]

-�.▲�ション「アプリケーションの実行」~
アプリケーションのフルパスを指定。~

&ref("./アプリケーションの実行.png");

-��PADでプログラムが起動してもPADコンソールがデスクトップに表示されたままになるので
ALT+F4で終了させる

&ref("./コンソール終了.png");
&ref("./コンソールの終了.png");

-�L榲�の画面の表示を待つ。そのWindowをUI要素で指定する。

&ref("./Window待機1.png");

-�こ�層メニューバーからメニューを選択。3階層なので、アクションが3つ必要

&ref("./メニュー選択.png");

-�Σ爾笄�を2つ入力してEnterを入力

&ref("./キー入力.png");

-�А銑� 同じアクションを2つ実行

&ref("./テキストボックス入力.png");

***メニューバーから選択をサーバアドレスが表示している個所(画像)をクリックするように変更 [#ka1ab209]

-メニューバーから選択3つのアクションの無効化

&ref("./アクション無効化.png");

-サーバアドレス部を画像して認識させクリックする

&ref("./画像にマウスを移動してクリック.png");


&ref("./画像にマウスを移動してクリック2.png");

***保存画像の削除 [#yc6387a1]

&ref("./保存画像削除.png");

&ref("./保存画像削除2.png");

***ショートカット作成 [#tf91efdd]

-Windows11
PowerShellを作成して以下のようなスクリプトを作成してそのショートカットを作成する。

-kidou.ps1

 # 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()
 }

-Windows10の場合

さらに、以下のようなバッチを作成してそのショートカットを作成する

--kidou.bat

 powershell -ExecutionPolicy Bypass -File "kidou.ps1"


***参考(ショートカット) [#u955592a]

-https://note.com/wynaut_952348/n/nc4b266cc666d

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS