Launch Metro style apps using powershell

2019-05-07 23:25发布

I am trying to write a powershell script for windows 10 that will automatically launch a Metro-style app. The Start-Process cmdlet seems like it should work, but I cannot get it to launch anything unless I provide a path to the .exe

For example, the following input works:

    Start-Process 'C:\Program Files\Internet Explorer\iexplore.exe'

Unfortunately, Metro style apps do not have an executable file. What file do I need to use to launch them? If I wanted to launch Windows Store for example, how would I do that?

Thanks

5条回答
再贱就再见
2楼-- · 2019-05-07 23:40

I don't know of a truly universal way to do this, but you can probably figure it out with a couple intermediary checks.

note: I hate using PowerShell, so pardon the weirdness of calling PS stuff from CMD

Step 1: Figure out what apps you have.

powershell Get-AppXPackage will generate the list of all of them. Let's say you specifically want to launch the Desktop App Converter so you can handle some Centennial patching while leveraging automation. So I'll query against the list of AppXs for something that might match using findstr to filter what comes back.

Step 2: Figure out if you already have the app you want

powershell Get-AppXPackage | findstr /i Desktop

While that gives me back numerous results, I can clearly see set of matches returned as:

Name              : Microsoft.DesktopAppConverter
PackageFullName   : Microsoft.DesktopAppConverter_2.1.1.0_x64__8wekyb3d8bbwe
InstallLocation   : C:\Program Files\WindowsApps\Microsoft.DesktopAppConverter_2.1.1.0_x64__8wekyb3d8bbwe
PackageFamilyName : Microsoft.DesktopAppConverter_8wekyb3d8bbwe

If I didn't get anythign like this back, the natural next step is to get the darned thing :) So for the next step, this could get tricky, and your mileage may vary:

Step 3: Find the location the app exists where you can actually call it: Why am I doing this? Because if I try to run it from the path returned from the AppXPackage query, I'll get "Access is denied."

where DesktopAppConverter

C:\Users\user name\AppData\Local\Microsoft\WindowsApps\DesktopAppConverter.exe 

You should then be able to take that resulting path and be able to run it from there.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-05-07 23:52

Store Apps can only be started by the shell. Try this:

explorer.exe shell:AppsFolder\Microsoft.WindowsAlarms_8wekyb3d8bbwe!App
查看更多
祖国的老花朵
4楼-- · 2019-05-07 23:55

You can locate the command to use with Start-Process by navigating here in the registry: Computer\HKEY_CLASSES_ROOT\Extensions\ContractId\Windows.Protocol\PackageId

Then expand ActivatableClassId, then the app, then in the CustomProperties folder look at the value for Name.

Start-Process must be run with PowerShell as is not recognised in CMD.

I used this to start the Windows Mail app.

查看更多
劫难
5楼-- · 2019-05-07 23:56

You have to provide the name of the appx. For example, to launch windows store in Win8/Win10, use the following code:

    Start-Process ms-windows-store:

I was amazed at how little documentation there is for launching metro style apps.

查看更多
贪生不怕死
6楼-- · 2019-05-07 23:56

If you download the Windows SDK, there is an executable in there called: microsoft.windows.softwarelogo.appxlauncher.exe which can be used to launch UWP apps.

The format is: microsoft.windows.softwarelogo.appxlauncher.exe <packageFamilyName>!App

You can get the packageFamilyName of your app by looking at kayleeFrye_OnDeck's answer.

查看更多
登录 后发表回答