5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Power Automate Desktopを最新版に更新するフロー

Posted at

Power Automate Desktop は、リリース以来、新しい機能が次々に追加されています。しかし、2021年4月28日現在、自動更新する機能がなく、更新時には、公式サイトからのインストーラーのダウンロードおよびインストールを実施する必要があります。
(Power Automate Desktop の更新を Power Automate Desktop で自動化する方法 - Qiita)

上記記事では、この作業をフロー化し、Power Automate Desktop(以下PAD)から1クリックで実行可能にしています。ただ事前にバッチファイルの作成が必要、実行結果が不明という難点がまだ残っています。これを改善するのが本記事の目的です。以下の改変をしたフローを提供します。

  • バッチファイル作成もフローから行う(事前作成が不要になる)
  • ログファイルを出力する(実行結果が確認可能になる)

この記事の手順では、事前準備は「PAD更新フローの作成」をするだけで、実際の更新は作成したフローを実行するだけです。

PAD更新フローの作成

フローの作成手順は以下のようになります(基本的には通常のフロー作成と同じ手順です)。

  1. Power Automate Desktopコンソールを開きます。
  2. 「新しいフロー」をクリックします。フロー名を指定(例えば UpdatePowerAutomationDesktop など)し、「作成」をクリックします。
  3. 何もアクションがない状態でフローデザイナーが開きます。以下のコードをコピーし、フローデザイナーにペーストします。
  4. 「保存」をしてからフローデザイナーを閉じます。

貼り付けるコードは以下です。

Folder.GetSpecialFolder SpecialFolder: Folder.SpecialFolder.DesktopDirectory SpecialFolderPath=> SpecialFolderPath
DateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
Text.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''yyyyMMdd''' Result=> DateStr
Folder.Create FolderPath: SpecialFolderPath FolderName: $'''Update-PAD-%DateStr%''' Folder=> WorkingFolderPath
File.WriteText File: $'''%WorkingFolderPath%\\PADInstall.log''' TextToWrite: $'''Create \"PADInstall.bat\"''' AppendNewLine: True IfFileExists: File.IfFileExists.Overwrite Encoding: File.FileEncoding.UTF8NoBOM
File.WriteText File: $'''%WorkingFolderPath%\\PADInstall.bat''' TextToWrite: $'''Setup.Microsoft.PowerAutomateDesktop.exe -Silent -Install -ACCEPTEULA''' AppendNewLine: True IfFileExists: File.IfFileExists.Overwrite Encoding: File.FileEncoding.UTF8NoBOM
File.WriteText File: $'''%WorkingFolderPath%\\PADInstall.log''' TextToWrite: $'''Download \"Setup.Microsoft.PowerAutomateDesktop.exe\"''' AppendNewLine: True IfFileExists: File.IfFileExists.Append Encoding: File.FileEncoding.UTF8NoBOM
Web.DownloadToFolder Url: $'''https://go.microsoft.com/fwlink/?linkid=2102613''' DestinationFolder: WorkingFolderPath ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False UserAgent: $'''Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20100312 Firefox/3.6''' Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False DownloadedFile=> DownloadedFile
File.WriteText File: $'''%WorkingFolderPath%\\PADInstall.log''' TextToWrite: $'''Run \"PADInstall.bat\"''' AppendNewLine: True IfFileExists: File.IfFileExists.Append Encoding: File.FileEncoding.UTF8NoBOM
System.RunDOSCommand DOSCommandOrApplication: $'''%WorkingFolderPath%\\PADInstall.bat ''' WorkingDirectory: WorkingFolderPath StandardOutput=> CommandOutput StandardError=> CommandErrorOutput ExitCode=> CommandExitCode
File.WriteText File: $'''%WorkingFolderPath%\\PADInstall.log''' TextToWrite: $'''Exit Code: %CommandExitCode%''' AppendNewLine: True IfFileExists: File.IfFileExists.Append Encoding: File.FileEncoding.UTF8NoBOM
File.WriteText File: $'''%WorkingFolderPath%\\PADInstall.log''' TextToWrite: $'''Output: %CommandOutput%''' AppendNewLine: True IfFileExists: File.IfFileExists.Append Encoding: File.FileEncoding.UTF8NoBOM
File.WriteText File: $'''%WorkingFolderPath%\\PADInstall.log''' TextToWrite: $'''Error Output: %CommandErrorOutput%''' AppendNewLine: True IfFileExists: File.IfFileExists.Append Encoding: File.FileEncoding.UTF8NoBOM

コードを貼り付けた時点で、フローデザイナーは次のようになります。

image.png

PAD更新の実行

  1. Power Automate Desktopコンソールから、作成したフローを実行します。
    image.png
  2. 実行中に、Power Automate Desktopがシステムに変更を加えてよいかという確認ダイアログが表示されます。許可します。
  3. 完了を待ちます。

実行結果の確認

このフローは以下を行います。

  1. デスクトップに Install-PAD-年月日 フォルダを作成します。
  2. 上記フォルダに PADInstall.bat ファイルを作成します。
  3. 上記フォルダに Setup.Microsoft.PowerAutomateDesktop.exe ファイルをダウンロードします(インストーラです)。
  4. 上記フォルダに PADInstall.log ファイルを作成します(ログファイルです)。

実行結果は、以下で確認できます。

  • デスクトップ上に上記フォルダがある。
  • フォルダ内に上記3ファイルがある。
  • PADInstall.log ファイル内で Exit Code: 0 と出力されている。

Exit Code が0ではない時は Error Output: 以降を確認してください。おそらく、なにかの理由でインストールが失敗しているでしょう。3ファイル揃っていないか Exit Code が出力されていない時には、おそらくインストーラ実行まで行っていないでしょう。 PADInstall.log の出力がどこまでされているかで、どのタイミングで失敗したのかを確認してください。

PADInstall.log に出力されるログ内容は、例えば以下のようになります(これは成功時のログです)。

Create "PADInstall.bat"
Download "Setup.Microsoft.PowerAutomateDesktop.exe"
Run "PADInstall.bat"
Exit Code: 0
Output: 
C:\Users\tsuka\Desktop\Update-PAD-20210518>Setup.Microsoft.PowerAutomateDesktop.exe -Silent -Install -ACCEPTEULA 

Error Output: 

なお実行後は、デスクトップの Install-PAD-年月日 フォルダは中身ごと削除して構いません。削除しなくても動作に問題はありません(仮に同じ日に再実行したとしても、すべてのファイルが上書きされます)が、インストーラは100MB程度になるのでディスク容量の観点から適宜消した方がよいでしょう。

参考

ほとんどのアイデアと実装は @maekawawawa 氏による以下の記事からのものです。この記事では冒頭で書いた通り「バッチファイル作成」「ログファイル出力」を加えただけです。

5
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?