Power Platform CommunityにPower Automate Desktop(PAD)からストアアプリ版のPower BIを実行したいとの質問がありました。
通常のアプリケーションはパスを指定して実行できますが、ストアアプリではそれができません。例えばストアアプリの「切り取り & スケッチ」の実行ファイルのパスは下記の通りですが、このパスを指定しても実行時にはエラーが発生します。
C:\Program Files\WindowsApps\Microsoft.ScreenSketch_10.2008.2277.0_x64__8wekyb3d8bbwe\ScreenSketch.exe
このようなストアアプリを実行したい場合、最も簡単なのはアプリに関連付けられたURIスキームを指定することです。
上記の「切り取り & スケッチ」の場合は、アプリケーション パスに「ms-screensketch:」(最後の :(コロン) は必須)を指定することで、PADからアプリケーションを実行できます。
アプリに関連付けられたURIスキームの取得方法
URIスキームは下記レジストリ以下にある「CustomProperties」キーから「Name」エントリの値として取得できます。
HKEY_CLASSES_ROOT\Extensions\ContractId\Windows.Protocol\PackageId\
例えば「切り取り & スケッチ」の場合は下記の通りです。
[HKEY_CLASSES_ROOT\Extensions\ContractId\Windows.Protocol\PackageId\Microsoft.ScreenSketch_10.2008.2277.0_x64__8wekyb3d8bbwe\ActivatableClassId\App.AppXwnmr9952bptdbfyz5zk8cebdbtcyf7na.mca\CustomProperties] "Name"="ms-screensketch"
CustomPropertiesキーを1つずつ確認していくのは大変ですが、下記PowerShellコードを実行することで、必要な値のみを抜き出せます。
(Get-ChildItem -Path "Registry::HKCR\Extensions\ContractId\Windows.Protocol\PackageId\" -Include "CustomProperties" -Recurse | Get-ItemProperty).Name
AppUserModelId(AUMID)によるストアアプリの実行方法
下記記事でも書いている通り、ストアアプリはAppUserModelId(Application User Model ID)を指定することでも実行できます。
例えば「切り取り & スケッチ」の場合はAUMIDが「Microsoft.ScreenSketch_8wekyb3d8bbwe!App」なので、アプリケーション パスに下記を指定することで、PADからアプリケーションを実行できます。
shell:AppsFolder\Microsoft.ScreenSketch_8wekyb3d8bbwe!App
上記記事のスクリプトを一部変更して、下記フローのようにアプリ名を指定して実行することもできます。
# アプリ名を指定してストアアプリを実行するPADフロー
Display.InputDialog Title: $'''アプリ名入力''' Message: $'''実行するアプリ名を入力してください。''' DefaultValue: $'''切り取り''' InputType: Display.InputType.SingleLine IsTopMost: True UserInput=> AppName ButtonPressed=> ButtonPressed
IF ButtonPressed = $'''OK''' THEN
IF AppName.Length > 0 THEN
# VBSでアプリのAppUserModelId(AUMID)を取得
System.RunVBScript VBScriptCode: $'''Option Explicit
Dim itm
With CreateObject(\"Shell.Application\").Namespace(\"shell:AppsFolder\")
For Each itm In .Items
If InStr(LCase(itm.Name), LCase(\"%AppName%\")) Then
WScript.Echo itm.Path
Exit For
End If
Next
End With''' ScriptOutput=> AUMID ScriptError=> ScriptError
IF AUMID.IsEmpty = $'''False''' THEN
Text.Trim Text: AUMID TrimOption: Text.TrimOption.Both TrimmedText=> AUMID
System.RunApplication ApplicationPath: $'''shell:AppsFolder\\%AUMID%''' WindowStyle: System.ProcessWindowStyle.Normal ProcessId=> AppProcessId
ELSE
Display.ShowMessageWithTimeout Message: $'''アプリ名「%AppName%」が見つかりませんでした。''' Icon: Display.Icon.Warning Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True Timeout: 3 ButtonPressed=> ButtonPressed2
END
END
END
上記フローでは「shell:AppsFolder」経由でアプリを実行していますが、AUMIDが分かればPowerShell経由でIApplicationActivationManager::ActivateApplicationメソッドを呼び出すことでもストアプリを実行できます。
ただ、処理後にアプリを終了する等、プロセスIDを使って何か処理を行う必要がない場合は「shell:AppsFolder」経由での実行で十分だと思います。
# アプリ名を指定してストアアプリを実行するPADフロー
Display.InputDialog Title: $'''アプリ名入力''' Message: $'''実行するアプリ名を入力してください。''' DefaultValue: $'''切り取り''' InputType: Display.InputType.SingleLine IsTopMost: True UserInput=> AppName ButtonPressed=> ButtonPressed
IF ButtonPressed = $'''OK''' THEN
IF AppName.Length > 0 THEN
# VBSでアプリのAppUserModelId(AUMID)を取得
System.RunVBScript VBScriptCode: $'''Option Explicit
Dim itm
With CreateObject(\"Shell.Application\").Namespace(\"shell:AppsFolder\")
For Each itm In .Items
If InStr(LCase(itm.Name), LCase(\"%AppName%\")) Then
WScript.Echo itm.Path
Exit For
End If
Next
End With''' ScriptOutput=> AUMID ScriptError=> ScriptError
IF AUMID.IsEmpty = $'''False''' THEN
Text.Trim Text: AUMID TrimOption: Text.TrimOption.Both TrimmedText=> AUMID
# IApplicationActivationManager::ActivateApplicationメソッドでアプリを実行することでプロセスIDを取得
System.RunPowershellScript Script: $'''$code = @\"
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
namespace ExecStoreApp
{
[ComImport, Guid(\"2e941141-7f97-4756-ba1d-9decde894a3d\"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IApplicationActivationManager
{
IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] UInt32 options, [Out] out UInt32 processId);
}
[ComImport, Guid(\"45BA127D-10A8-46EA-8AB7-56EA9078943C\")]
public class ApplicationActivationManager : IApplicationActivationManager
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)/*, PreserveSig*/]
public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] UInt32 options, [Out] out UInt32 processId);
}
}
\"@
Add-Type $code
$processId = 0
$aam = New-Object ExecStoreApp.ApplicationActivationManager
$res = $aam.ActivateApplication(\"%AUMID%\", $null, 0, [ref]$processId)
Write-Output $processId''' ScriptOutput=> ProcessId ScriptError=> ScriptError2
Text.Trim Text: ProcessId TrimOption: Text.TrimOption.Both TrimmedText=> ProcessId
Display.ShowMessageWithTimeout Message: $'''起動したアプリのプロセスID:%ProcessId%''' Icon: Display.Icon.Information Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True Timeout: 3 ButtonPressed=> ButtonPressed3
System.TerminateProcessById ProcessId: ProcessId
ELSE
Display.ShowMessageWithTimeout Message: $'''アプリ名「%AppName%」が見つかりませんでした。''' Icon: Display.Icon.Warning Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True Timeout: 3 ButtonPressed=> ButtonPressed2
END
END
END
上記の通り、URIスキームやAUMIDを指定することでPADからストアプリを実行できますので、ストアアプリの制御が必要な際には是非お試しください。



























この記事へのコメントはありません。