【问题标题】:How to Start a Universal Windows App (UWP) from PowerShell in Windows 10?如何在 Windows 10 中从 PowerShell 启动通用 Windows 应用程序 (UWP)?
【发布时间】:2017-10-23 15:38:08
【问题描述】:

在 PowerShell 中,如果我运行 Get-AppxPackage,我会得到一个已安装的 UWP 应用程序 的列表,包括我的。 例如:

Name              : TonyHenrique.tonyuwpteste
Publisher         : CN=tTony
Architecture      : X64
ResourceId        :
Version           : 1.1.12.0
PackageFullName   : TonyHenrique.tonyuwpteste_1.1.12.0_x64__h3h3tmhvy8gfc
InstallLocation   : C:\Program Files\WindowsApps\TonyHenrique.tonyuwpteste_1.1.12.0_x64__h3h3tmhvy8gfc
IsFramework       : False
PackageFamilyName : TonyHenrique.tonyuwpteste_h3h3tmhvy8gfc
PublisherId       : h3h3tmhvy8gfc
IsResourcePackage : False
IsBundle          : False
IsDevelopmentMode : False
Dependencies      : {Microsoft.NET.CoreRuntime.2.1_2.1.25801.2_x64__8wekyb3d8bbwe, Microsoft.VCLibs.140.00.Debug_14.0.25805.1_x64__8wekyb3d8bbwe,
                    TonyHenrique.tonyuwpteste_1.1.12.0_neutral_split.scale-100_h3h3tmhvy8gfc}
IsPartiallyStaged : False
SignatureKind     : Developer
Status            : Ok

现在我想启动这个应用程序。

如何在 PowerShellcmd 中执行此操作?

【问题讨论】:

标签: powershell uwp


【解决方案1】:

在开发过程中,我遇到过应用家族名称偶尔会发生变化的情况。您可以通过简单的查找可靠地按名称启动应用程序:

  • 命令

    powershell.exe explorer.exe shell:AppsFolder\$(get-appxpackage -name YourAppName ^| select -expandproperty PackageFamilyName)!App
    
  • Powershell

    explorer.exe shell:AppsFolder\$(get-appxpackage -name YourAppName | select -expandproperty PackageFamilyName)!App
    

【讨论】:

  • 如果它是您的应用程序或特定情况下有效,但不能普遍使用,因为没有给出!App。例如Microsoft.BingNews_8wekyb3d8bbwe!AppexNews
  • 看起来 !Appx 或 !AppxNews 后缀可以在 AppxManifest.xml 中找到关联的应用程序标记:
【解决方案2】:

借助 Windows 10 Fall Creators Update 1709(内部版本 16299),您现在可以为您的 UWP 应用定义应用执行别名,因此您可以从 cmd 或 powershell 轻松启动它:

<Extensions>
    <uap5:Extension
      Category="windows.appExecutionAlias"
      StartPage="index.html">
      <uap5:AppExecutionAlias>
        <uap5:ExecutionAlias Alias="MyApp.exe" />
      </uap5:AppExecutionAlias>
    </uap5:Extension>
</Extensions>

此外,我们现在支持 UWP 应用的命令行参数。您可以从 OnActivated 事件中读取它们:

async protected override void OnActivated(IActivatedEventArgs args)
{
    switch (args.Kind)
    {
        case ActivationKind.CommandLineLaunch:
            CommandLineActivatedEventArgs cmdLineArgs = 
                args as CommandLineActivatedEventArgs;
            CommandLineActivationOperation operation = cmdLineArgs.Operation;
            string cmdLineString = operation.Arguments;
            string activationPath = operation.CurrentDirectoryPath;

见博文: https://blogs.windows.com/buildingapps/2017/07/05/command-line-activation-universal-windows-apps/

【讨论】:

  • 我在这里有类似的问题posted,到目前为止还没有解决方案。我想知道您是否有任何解决方案/想法?谢谢。
【解决方案3】:

在 PowerShell 中试试这个:

start shell:AppsFolder\TonyHenrique.tonyuwpteste_h3h3tmhvy8gfc!App

【讨论】:

  • 根据您的回答,我最终使用了:explorer.exe shell:AppsFolder\TonyHenrique.tonyuwpteste_h3h3tmhvy8gfc!App
【解决方案4】:

如果您知道显示名称,则可以使用Get-StartApps,其中包含正确的后缀:

start "shell:AppsFolder\$(Get-StartApps "Groove Music" | select -ExpandProperty AppId)"

【讨论】:

    猜你喜欢
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    相关资源
    最近更新 更多