用法:

用法:

我知道如果我有 .appx 包文件,我可以通过 powershell 使用Add-AppxPackagecmdlet 安装它。但是,我只想按名称下载并安装 Microsoft Store 包。

我不想必须转到 Microsoft Store 页面,启动 Fiddler,开始下载,捕获 .appx 文件 URL,然后手动下载才能使用Add-AppxPackage。(查看 Windows OS Hub 是如何做到的这里

这可能很有趣 - 但不太可靠。我需要一个强大的可编写脚本的方法来管理 Windows Store 应用。

(有一些软件包只能通过 Microsoft Store 访问。其他所有软件包我都可以通过 Chocolatey 或直接 msi 下载获得。)

我还不能编写脚本的一个例子是安装HEIF 图像扩展(需要从 iPhone 查看图像格式:*.HEIC格式。

当我从 Windows 商店安装它时,它显示Get-AppxPackage

PS C:\Tools> Get-AppxPackage | Where-Object {$_.Name -eq "Microsoft.HEVCVideoExtension" }


Name              : Microsoft.HEVCVideoExtension
Publisher         : CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
Architecture      : X64
ResourceId        :
Version           : 1.0.31053.0
PackageFullName   : Microsoft.HEVCVideoExtension_1.0.31053.0_x64__8wekyb3d8bbwe
InstallLocation   : C:\Program Files\WindowsApps\Microsoft.HEVCVideoExtension_1.0.31053.0_x64__8wekyb3d8bbwe
IsFramework       : False
PackageFamilyName : Microsoft.HEVCVideoExtension_8wekyb3d8bbwe
PublisherId       : 8wekyb3d8bbwe
IsResourcePackage : False
IsBundle          : False
IsDevelopmentMode : False
NonRemovable      : False
Dependencies      : {Microsoft.VCLibs.140.00_14.0.27810.0_x64__8wekyb3d8bbwe}
IsPartiallyStaged : False
SignatureKind     : Store
Status            : Ok

我想要的是 cmdlet:Download-AppxPackage以便我可以执行以下操作:

Download-AppxPackage -Name "Microsoft.HEVCVideoExtension"

有人知道我该怎么做吗?

答案1

您现在可以使用温格特在 Windows 10 和 11 上安装 msstore 应用。使用winget search <app_name> --source=msstore进行搜索,然后使用应用的 ID 安装和升级应用。例如,要安装 Netflix:

  1. 首先,我用 进行了搜索winget search Netflix --source=msstore,发现应用程序 ID 是9WZDNCRFJ3TJ
  2. 我使用 安装应用程序winget install -e -i --id=9WZDNCRFJ3TJ --source=msstore
  3. 我用 升级应用程序winget upgrade -e -i --id=9WZDNCRFJ3TJ

答案2

store.rg-adguard.net是一个用于生成商店应用直接下载链接的 GUI。查看该页面的源代码,我们可以利用它们直接下载内容,但使用封装系列名称, 而不是姓名(在您的例子中,它将是Microsoft.HEVCVideoExtension_8wekyb3d8bbwe)。

function Download-AppxPackage {
[CmdletBinding()]
param (
  [string]$PackageFamilyName,
  [string]$Path
)
   
  process {
    $WebResponse = Invoke-WebRequest -Method 'POST' -Uri 'https://store.rg-adguard.net/api/GetFiles' -Body "type=PackageFamilyName&url=$($PackageFamilyName)&ring=Retail&lang=en-US" -ContentType 'application/x-www-form-urlencoded' -UseBasicParsing
    $LinksMatch = $WebResponse.Links | where {$_ -like '*_x64*.appx*'} | Select-String -Pattern '(?<=a href=").+(?=" r)'
    $DownloadLinks = @($LinksMatch.matches.Value)

    for ($i = 1; $i -le $DownloadLinks.Count; $i++) {
      Invoke-WebRequest -Uri $DownloadLinks[$i-1] -OutFile "$Path\$PackageFamilyName($i).appx"   
    }
  }
}

这仅限于 x64 版本,并且路径必须指向一个文件夹。它将下载包及其依赖项并将它们全部保存为封装系列名称n).appx

答案3

进一步构建 AJ 的答案。使用 powershell 从 windows 应用商店下载任何应用程序,只需提供商店中的 url 和保存路径即可。

用法:

Download-AppxPackage "https://www.microsoft.com/p/dynamic-theme/9nblggh1zbkw" "$ENV:USERPROFILE\Desktop"
C:\Users\user\Desktop\55888ChristopheLavalle.DynamicTheme_1.4.30233.0_neutral_~_jdggxwd41xcr0.AppxBundle
C:\Users\user\Desktop\55888ChristopheLavalle.DynamicTheme_1.4.30234.0_neutral_~_jdggxwd41xcr0.AppxBundle
C:\Users\user\Desktop\Microsoft.NET.Native.Framework.1.7_1.7.27413.0_x64__8wekyb3d8bbwe.Appx
C:\Users\user\Desktop\Microsoft.NET.Native.Runtime.1.7_1.7.27422.0_x64__8wekyb3d8bbwe.Appx
C:\Users\user\Desktop\Microsoft.Services.Store.Engagement_10.0.19011.0_x64__8wekyb3d8bbwe.Appx
C:\Users\user\Desktop\Microsoft.VCLibs.140.00_14.0.29231.0_x64__8wekyb3d8bbwe.App

代码:

function Download-AppxPackage {
[CmdletBinding()]
param (
  [string]$Uri,
  [string]$Path = "."
)
   
  process {
    $Path = (Resolve-Path $Path).Path
    #Get Urls to download
    $WebResponse = Invoke-WebRequest -UseBasicParsing -Method 'POST' -Uri 'https://store.rg-adguard.net/api/GetFiles' -Body "type=url&url=$Uri&ring=Retail" -ContentType 'application/x-www-form-urlencoded'
    $LinksMatch = $WebResponse.Links | where {$_ -like '*.appx*'} | where {$_ -like '*_neutral_*' -or $_ -like "*_"+$env:PROCESSOR_ARCHITECTURE.Replace("AMD","X").Replace("IA","X")+"_*"} | Select-String -Pattern '(?<=a href=").+(?=" r)'
    $DownloadLinks = $LinksMatch.matches.value 

    function Resolve-NameConflict{
    #Accepts Path to a FILE and changes it so there are no name conflicts
    param(
    [string]$Path
    )
        $newPath = $Path
        if(Test-Path $Path){
            $i = 0;
            $item = (Get-Item $Path)
            while(Test-Path $newPath){
                $i += 1;
                $newPath = Join-Path $item.DirectoryName ($item.BaseName+"($i)"+$item.Extension)
            }
        }
        return $newPath
    }
    #Download Urls
    foreach($url in $DownloadLinks){
        $FileRequest = Invoke-WebRequest -Uri $url -UseBasicParsing #-Method Head
        $FileName = ($FileRequest.Headers["Content-Disposition"] | Select-String -Pattern  '(?<=filename=).+').matches.value
        $FilePath = Join-Path $Path $FileName; $FilePath = Resolve-NameConflict($FilePath)
        [System.IO.File]::WriteAllBytes($FilePath, $FileRequest.content)
        echo $FilePath
    }
  }
}

这会正确下载中性和 x64 软件包,但未针对 arm 和 32 位系统进行测试。路径必须指向一个文件夹。它将下载软件包及其依赖项,并将它们全部保存为原始文件名,同时避免像 chrome 那样的名称冲突。

答案4

我发现了一些我认为值得注意的附加工具,希望对使用 Windows Sandbox 的其他人有用。

虽然我尝试在 Windows Sandbox 中手动安装 Windows Store,但由于缺少必需的组件而失败,但这个项目填补了所有空白:

git clone https://github.com/kkkgo/LTSC-Add-MicrosoftStore

在该文件夹中,只需运行Add-Store.cmd,您现在将在 Windows Sandbox 中的开始菜单上拥有一个可操作的 Store App,但它并不完整,因为还必须启动一些服务:

# 'config start=auto' is not required on Sandbox,
# but is useful for non-Sandbox environments.
SC config wuauserv start=auto
SC config bits start=auto
SC config cryptsvc start=auto
SC config trustedinstaller start=auto
SC start wuauserv
SC start bits
SC start cryptsvc
SC start trustedinstaller

最后,确保使用 Microsoft 帐户登录商店(按右上角的个人资料),之后您应该在 Windows Sandbox 内拥有一个功能齐全的 Windows Store 应用程序。

该项目是为 Windows Enterprise LTSC(长期服务渠道,专为 Windows 10 设备设计,其关键要求是功能和特性不会随时间而变化)构建的,与 Windows Sandbox 一样,它使用精简的功能集,但该项目在 Windows Sandbox 上完美运行。该项目安装了四个组件来实现这一点:

Microsoft Store
Store Purchase App
App Installer
Xbox Identity Provider

相关内容