Launch Metro style apps using powershell

匿名 (未验证) 提交于 2019-12-03 08:57:35

问题:

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

回答1:

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

explorer.exe shell:AppsFolder\Microsoft.WindowsAlarms_8wekyb3d8bbwe!App 


回答2:

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.



回答3:

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.



回答4:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!