windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序

windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序_第1张图片

windows桌面应用程序

windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序_第2张图片

With Windows 10’s Anniversary Update, Microsoft is making it possible for developers to convert traditional Windows desktop applications to Universal Windows Platform (UWP) applications. But anyone can do this with any app–not just developers.

借助Windows 10的周年更新 ,Microsoft使开发人员可以将传统的Windows桌面应用程序转换为通用Windows平台(UWP)应用程序。 但是任何人都可以使用任何应用程序执行此操作,而不仅仅是开发人员。

With Windows 10’s converter, just give it a .msi or .exe file and it’ll spit out a .appx package. You can then sideload this app on your own PC, or–if you’re the application’s developer–you can submit the resulting UWP app to the Windows Store. This feature will arrive for everyone with Windows 10’s Anniversary Update, bringing many “legacy” applications to the Windows Store.

使用Windows 10的转换器,只需为其提供.msi或.exe文件,它就会吐出.appx程序包。 然后,您可以在自己的PC上侧面加载此应用程序,或者-如果您是该应用程序的开发人员-您可以将生成的UWP应用程序提交到Windows应用商店。 Windows 10周年更新将为所有人提供此功能, 从而将许多“旧版”应用程序带到Windows应用商店 。

为什么要这样做 (Why You’d Want to Do This)

This feature is the end result of Microsoft’s Project Centennial, which is designed to bring those “legacy” Win32 and .NET Windows desktop applications to the Windows Store and the new Universal Windows Platform.

此功能是Microsoft Project Centennial的最终结果,该项目旨在将这些“旧版” Win32和.NET Windows桌面应用程序引入Windows应用商店和新的通用Windows平台。

You might wonder why anyone would want to convert a desktop application to a new UWP app. For one thing, only UWP apps are allowed in the Windows Store. This allows developers to get a lot more eyes on their apps, not to mention single-click installation, easy purchasing, and automatic updates.

您可能想知道为什么有人会想要将桌面应用程序转换为新的UWP应用程序。 一方面,Windows应用商店中仅允许使用UWP应用。 这使开发人员可以更加关注自己的应用程序,更不用说单击安装,轻松购买和自动更新了。

Microsoft’s new UWP application platform is sandboxed, but desktop apps you convert are not. These applications will have full access to your system, just like a traditional desktop application. As Microsoft’s documentation says: “As a UWP app, your app is able to do the things it could do as a classic desktop app. It interacts with a virtualized view of the registry and file system that’s indistinguishable from the actual registry and file system.”

Microsoft的新UWP应用程序平台已沙盒化,但您转换的桌面应用程序却没有。 这些应用程序将具有对系统的完全访问权限,就像传统的桌面应用程序一样。 正如Microsoft的文档所述 :“作为UWP应用,您的应用能够执行其作为经典桌面应用所能做的事情。 它与注册表和文件系统的虚拟化视图进行交互,这与实际的注册表和文件系统没有区别。”

局限性 (The Limitations)

There are some important limitations here. First, you can only do this on the Windows 10 Anniversary Update. For now, it’ll work with Windows 10 Insider Preview build 14316 and higher, so you’ll need to join the Windows Insider program and use an Insider Preview build of Windows 10.

这里有一些重要的限制。 首先,您只能在Windows 10周年更新中执行此操作。 目前,它可与Windows 10 Insider Preview内部版本14316和更高版本一起使用,因此您需要加入Windows Insider程序并使用Windows 10 Insider Preview内部版本 。

This feature also requires either the Professional or Enterprise editions of Windows 10. Windows 10 Home users won’t be able to use the Desktop App Converter. As of build 14316, it only worked on Windows 10 Enterprise, but support for Windows 10 Professional is coming. Currently, this tool can only be used on 64-bit versions of Windows, and the resulting AppX package can only be installed on 64-bit versions of Windows. This will change in future Insider builds of Windows 10.

此功能还需要Windows 10的专业版或企业版。Windows 10家庭用户将无法使用Desktop App Converter。 从内部版本14316开始,它仅适用于Windows 10 Enterprise,但即将支持Windows 10 Professional。 当前,此工具只能在Windows的64位版本上使用,并且生成的AppX软件包只能在Windows的64位版本上安装。 这将在Windows 10的将来Insider版本中改变。

The resulting applications are intended for Windows 10 PCs. They won’t work on Windows 10 Mobile smartphones, Xbox One, HoloLens, Surface Hub, and the other Windows 10 platforms that run UWP apps. However, if you’re a developer, Microsoft offers a path to getting your desktop application into a cross-platform UWP application: “If you choose to move all of your app’s functionality out of the full-trust partition of the app and into the app container partition, then your app will be able to run on any Windows 10 device.”

生成的应用程序适用于Windows 10 PC。 它们不适用于Windows 10移动智能手机,Xbox One,HoloLens,Surface Hub和其他运行UWP应用的Windows 10平台。 但是,如果您是开发人员,Microsoft提供了一种将桌面应用程序转换为跨平台UWP应用程序的途径:“如果您选择将应用程序的所有功能移出应用程序的完全信任分区,并移至应用程序的应用容器分区,那么您的应用将可以在任何Windows 10设备上运行。”

However, some types of application behavior aren’t supported. An application can’t require it be run as Administrator or use other types of low-level system access. Microsoft provides a list of behaviors that aren’t allowed.

但是,不支持某些类型的应用程序行为。 应用程序不能要求其以管理员身份运行或使用其他类型的低级系统访问权限。 Microsoft提供了不允许的行为列表。

如何设置桌面应用转换器 (How to Set Up the Desktop App Converter)

Assuming you’re using a new enough build of the Windows 10 Insider Preview, you can download and install the Desktop App Converter from Microsoft’s Developer site. Download both the DesktopAppConverter.zip and BaseImage-14316.wim files. Extract the downloaded DesktopAppConverter.zip file to a folder on your computer and place the BaseImage file in the same directory. (If there’s a new build of Windows 10 available, you should see a new BaseImage file. You’ll need to use the BaseImage file with the same version number as your installed build of Windows 10.)

假设您正在使用足够新的Windows 10 Insider Preview版本,则可以从Microsoft的Developer网站下载并安装Desktop App Converter 。 下载DesktopAppConverter.zip和BaseImage-14316.wim文件。 将下载的DesktopAppConverter.zip文件解压缩到计算机上的文件夹中,然后将BaseImage文件放置在同一目录中。 (如果有可用的Windows 10的新版本,则应该看到一个新的BaseImage文件。您需要使用与已安装的Windows 10的版本号相同的BaseImage文件。)

You’ll also need to download and install the Windows 10 SDK.

您还需要下载并安装Windows 10 SDK 。

windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序_第3张图片

Next, open a PowerShell window as Administrator. To do so, open the Start menu, search for “PowerShell,” right-click its shortcut, and select “Run as Administrator.”

接下来,以管理员身份打开PowerShell窗口。 为此,请打开“开始”菜单,搜索“ PowerShell”,右键单击其快捷方式,然后选择“以管理员身份运行”。

Change PowerShell’s execution policy by running the following command. Agree to the change by typing y afterwards.

通过运行以下命令来更改PowerShell的执行策略。 稍后输入y同意更改。

Set-ExecutionPolicy bypass

Run the command below, replacing C:\Users\NAME\Downloads\DesktopAppConvertor with the path to the directory on your computer:

运行以下命令,将C:\Users\NAME\Downloads\DesktopAppConvertor替换为计算机上目录的路径:

cd -Path C:\Users\NAME\Downloads\DesktopAppConvertor

Set up the Desktop App Converter by running the following command:

通过运行以下命令来设置Desktop App Converter:

.\DesktopAppConverter.ps1 -Setup -BaseImage .\BaseImage-14316.wim

If you’re asked to reboot while running any of these commands, reboot your computer and then run the command again.

如果在运行这些命令时要求重新启动计算机,请重新启动计算机,然后再次运行该命令。

windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序_第4张图片

如何转换桌面应用程序 (How to Convert a Desktop Application)

You can now run the DesktopAppConverter.ps1 script from an Administrator PowerShell window to convert a desktop application to a UWP application in a single command. You’ll need the application’s installer to do this. As an example, we’ll use VLC here.

现在,您可以从Administrator PowerShell窗口运行DesktopAppConverter.ps1脚本,以单个命令将桌面应用程序转换为UWP应用程序。 您将需要应用程序的安装程序来执行此操作。 例如,我们将在这里使用VLC。

To view the detailed list of options, you can run the following command at any time:

要查看选项的详细列表,您可以随时运行以下命令:

get-help .\DesktopAppConverter.ps1 -detailed

Here’s a command you can use and adjust for your application:

这是您可以为应用程序使用和调整的命令:

.\DesktopAppConverter.ps1 -ExpandedBaseImage C:\ProgramData\Microsoft\Windows\Images\BaseImage-14316
 –Installer C:\Installer\MyApp.exe -InstallerArguments "/S" -Destination C:\Output\MyApp
 -PackageName "MyApp" -Publisher "CN=" -Version 0.0.0.1 -MakeAppx -Verbose

You’ll need to adjust the command to add your own publisher name, version, package name, and point it at the installer file and destination directory you prefer. The -InstallerArguments "/S" option here passes the /S switch to the installer, which makes many application installers install silently without any user input. Applications must be installable without any user input or you can’t convert them.

您需要调整命令以添加自己的发布者名称,版本,程序包名称,并将其指向您喜欢的安装程序文件和目标目录。 这里的-InstallerArguments "/S"选项将/S开关传递给安装程序,这使许多应用程序安装程序在没有任何用户输入的情况下静默安装。 应用程序必须可在没有任何用户输入的情况下安装,否则您将无法转换它们。

The application’s installer should be in its own directory without any other files, as the files in the same directory as the installer will be copied into the resulting .appx package.

应用程序的安装程序应位于其自己的目录中,没有任何其他文件,因为与安装程序位于同一目录中的文件将被复制到生成的.appx包中。

For example, we’re using VLC here, so here’s the command we’d use:

例如,我们在这里使用VLC,因此这是我们要使用的命令:

.\DesktopAppConverter.ps1 -ExpandedBaseImage C:\ProgramData\Microsoft\Windows\Images\BaseImage-14316
 –Installer C:\Users\chris\Downloads\vlc\vlc-2.2.2-win32.exe -InstallerArguments "/S" -Destination C:\Output\VLC
 -PackageName "VLC" -Publisher "CN=VideoLAN" -Version 0.2.2.2 -MakeAppx -Verbose
windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序_第5张图片

The tool will give you an .appx package, which is the UWP version of the app.

该工具将为您提供.appx包,这是应用程序的UWP版本。

windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序_第6张图片

如何在不签名的情况下安装应用 (How to Install the App Without Signing It)

You’re normally required sign apps with a valid signature before they can be installed. Microsoft recommends creating a self-signed certificate and signing the app with that on your computer. You can do that using the instructions below, if you like.

通常,要求您先使用有效签名对应用进行签名,然后才能进行安装。 Microsoft建议创建一个自签名证书,并使用您计算机上的证书对应用程序进行签名。 如果愿意,可以按照以下说明进行操作。

However, if you just want to install the app on your own computer, you can do this yourself faster, without messing with any signatures. Windows 10 allows you to install apps without signing them if you’re installing an “unpackaged” app from a directory.

但是,如果您只想在自己的计算机上安装该应用程序,则可以自己完成此操作,而不会弄乱任何签名。 如果从目录中安装“未打包”的应用程序,则Windows 10允许您安装应用程序而无需对其进行签名。

To do this, open a PowerShell window as Administrator and run the following command:

为此,请以管理员身份打开PowerShell窗口并运行以下命令:

Add-AppxPackage -Path C:\Path\to\AppxManifest.xml -Register

You’ll find the AppxManifest.xml file next to the Application.appx file in the output directory you specified.

您可以在指定的输出目录中的Application.appx文件旁边找到AppxManifest.xml文件。

You can now launch the application from your Start menu. It will be a “Windows app” instead of a “Desktop app,” but it will otherwise look and work like a normal desktop app.

现在,您可以从“开始”菜单启动应用程序。 它将是“ Windows应用程序”,而不是“桌面应用程序”,但在外观和工作方式上将与普通的桌面应用程序相似。

windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序_第7张图片

如何签名和安装应用程序 (How to Sign and Install the App)

You don’t need to follow these instructions if you’ve already installed the application. This is the harder way.

如果您已经安装了该应用程序,则无需遵循这些说明。 这是更困难的方法。

You can normally only install an .appx package if it has a valid signature. Microsoft recommends using the signtool.exe application included with the Windows 10 SDK to create a self-signed certificate, which will allow you to install and test the application on your own computer.

通常,只有具有有效签名的.appx软件包才能安装。 Microsoft建议使用Windows 10 SDK随附的signtool.exe应用程序来创建自签名证书,该证书将允许您在自己的计算机上安装和测试该应用程序。

Just open a Command Prompt window as Administrator and run the following commands to create a self-signed certificate and sign the .appx package with it:

只需以管理员身份打开“命令提示符”窗口,然后运行以下命令来创建自签名证书,并使用它对.appx包进行签名:

cd "C:\Program Files (x86)\Windows Kits\10\bin\x64"
MakeCert.exe -r -h 0 -n "CN=Publisher" -eku 1.3.6.1.5.5.7.3.3 -pe -sv my.pvk my.cer
pvk2pfx.exe -pvk my.pvk -spc my.cer -pfx my.pfx
signtool.exe sign -f my.pfx -fd SHA256 -v C:\Path\to\application.appx

Note that the publisher you specify–that’s the "CN=Publisher" –must match the publisher you specified earlier when creating the AppX file. So, continuing with our VLC example from above, we’d have to use "CN=VideoLAN" .

请注意,您指定的发布者(即"CN=Publisher"必须与创建AppX文件时先前指定的"CN=Publisher"者匹配。 因此,从上面继续我们的VLC示例,我们将不得不使用"CN=VideoLAN"

You’ll be asked to enter a password. You can just leave the password blank.

系统将要求您输入密码。 您可以将密码留空。

windows桌面应用程序_如何将Windows桌面应用程序转换为通用Windows应用程序_第8张图片

You can now install the .appx package in a PowerShell (Administrator) window with the Add-AppxPackage command:

现在,您可以使用Add-AppxPackage命令在PowerShell(管理员)窗口中安装.appx软件包:

Add-AppxPackage C:\Path\to\application.appx


This feature can be used by anyone, but only developers–and maybe some system administrators–will want to go this route. Luckily, the process is extremely easy for developers.

任何人都可以使用此功能,但只有开发人员(也许还有一些系统管理员)才愿意采用此功能。 幸运的是,该过程对于开发人员而言非常容易。

翻译自: https://www.howtogeek.com/250041/how-to-convert-a-windows-desktop-app-to-a-universal-windows-app/

windows桌面应用程序

你可能感兴趣的:(java,python,windows,linux,大数据)