Power Automate Desktop

更新日2024-11-08 (金) 11:24:35
作成日:2024年11月7日

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

インストール

  • Windows11

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

  • Windows10

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

起動

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

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

起動.png

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

起動2.png

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

起動3.png

以下の作成画面が開く

&ref(): File not found: "起動4.png" at page "Windows_Router Memo/Power Automate Desktop";

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

起動5.png

サンプル作成

アクション内容

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

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

アクション内容入力

  • ①アクション「アプリケーションの実行」
    アプリケーションのフルパスを指定。

アプリケーションの実行.png

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

コンソールの終了.png

  • ③目的の画面の表示を待つ。そのWindowをUI要素で指定する。

Window待機1.png

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

メニュー選択.png

  • ⑥下や↓を2つ入力してEnterを入力

キー入力.png

  • ⑦~⑨ 同じアクションを2つ実行

テキストボックス入力.png

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

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

アクション無効化.png

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

画像にマウスを移動してクリック.png

画像にマウスを移動してクリック2.png

保存画像の削除

保存画像削除.png

保存画像削除2.png

ショートカット作成

  • 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"

参考(ショートカット)


添付ファイル: fileアクション無効化.png 3件 [詳細] file保存画像削除2.png 5件 [詳細] file保存画像削除.png 5件 [詳細] file画像にマウスを移動してクリック2.png 4件 [詳細] file画像にマウスを移動してクリック.png 5件 [詳細] fileコンソールの終了.png 6件 [詳細] file起動5.png 7件 [詳細] file起動3.png 5件 [詳細] file起動2.png 7件 [詳細] file起動.png 5件 [詳細] fileメニュー選択.png 4件 [詳細] fileテキストボックス入力.png 4件 [詳細] fileキー入力.png 8件 [詳細] fileアプリケーションの実行.png 5件 [詳細] fileWindow待機1.png 5件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2024-11-08 (金) 11:24:35