Start Winui 3 App from command line with arguments

276 views Asked by At

My application is packaged and deployed using a local msix installer. The installer works fine and the app runs fine.

For testing and maintenance scenarios, I need to be able to run the app from the terminal using extra command line arguments. The arguments are parsed in the App.OnLaunched handler using Environment.GetCommandLineArgs();.

The people using this maintenance mode are not software engineers nor IT specialists. What is the best way for me to instruct them how to run such mode?

More context:
After digging, I found that I could run the maintenance mode by running the exe from its obscure install location, for example:
C:\Program Files\WindowsApps\27984f1c-bb26-4e2b-b989-78304f1f716e_1.0.7.0_x64__45c2krxqwh2t0

It looks like this install folder name follows a convention, the first part is an ID defined in the appxmanifest, then the package version, then the platform. Unfortunately, the last part (45c2krxqwh2t0) seems random.

I obviously cannot guess this folder location and copy it in the test protocol that I give the technicians for maintenance.

1

There are 1 answers

0
user2315856 On BEST ANSWER

Here is what I came up with thanks to Simon's comment:

$installPath = (Get-AppxPackage -Name "my-app-id-from-appxmanifest" -AllUsers).InstallLocation
$exeName = "MyApp.exe"
$appCommand = ($installPath + "\" + $exeName)

Write-Host "Starting: $($appCommand)"
Start-Process -FilePath $appCommand -ArgumentList 'my-args-to-set-virtual-mode'