Running 16-bit applications on Windows 10 64-bit
Published Sep 15 2020 06:54 PM 168K Views
Microsoft

monkeys.png

 

I wrote this post as a proof of concept and as a best effort to make a 16-bit application run on Windows 10 64-bit.

 

It will be demonstrated how to use a third-part open source framework called otya128 – winevdm, how to use MSIX, UWP Execution Alias and Packaging Support Framework.

 

prohibit.png

 

Please notice that Microsoft recommends using virtualization or 32-bit machines to run 16-bit applications.

 

This post is only a proof of concept and for informational and training purposes only and are provided "as is" without warranty of any kind, whether express or implied.

 

Download the 16-bit emulator

 

As 64-bit operating system does not have support for the Windows NT DOS Virtual Machine (NTVM) system component, the first step is to download the 16-bit emulator called otya128 – winevdm that is open source and available on GitHub:

 

github.png

 

https://github.com/otya128/winevdm

 

You can clone the repository and build yourself or download the build artifact from the AppVeyor repository  https://ci.appveyor.com/project/otya128/winevdm/history

 

If you opt to download the app from the AppVeyor repository, you need to choose what build you want:

 

winevdm01.png

 

Select the job:

 

winevdm02.png

 

And finally click on artifacts to download the artifact file:

 

winevdm03.png

 

Now, all you must do is to extract the files to a folder of your preference. I will extract the files in the following folder of the root of my C drive:

 

 

 

 C:\otvdm-master-1846

 

 

 

Installing Microsoft Visual Basic 3.0 IDE on Windows 10 64-bit

 

If you try to run the Visual Basic 3 installer (setup.exe), you will receive the following message telling that the application cannot run, since it is a 16-bit application and that the NTVDM is not available.

 

this app cannot run.png

 

We need to run the otvdm.exe passing as argument the application that we want to launch, in our case, the setup.exe of Visual Basic 3.0:

 

 

 

C:\otvdm-master-1846\otvdm.exe "C:\VB\VB.EXE"

 

 

 

Notice that now the Visual Basic 3.0 16-bit installer has been successfully launched:

 

setup1.png

 

We can proceed with the installation:

 

setup2.png

 

The default destination folder is C:\VB:

 

Setup3.png

 

There are no registry keys, and all the files will be copied to the C:\VB directory:

 

setup4.png

 

Done!!!! Visual Basic is successfully installed:

 

setup5.png

 

Click on Run Visual Basic 3.0 to launch VB3 on Windows 10 64-bit:

 

vb3 on win 10.png

 

 

Notice that despite of Visual Basic 3 is available on Start menu, you can’t directly launch the app from there, as the app is 16-bit:

 

start menu.png

 

In that case you need to run the following command:

 

 

 

C:\otvdm-master-1846\otvdm.exe "C:\VB\VB.EXE"

 

 

 

Improving the app distribution and providing a better user experience through MSIX

 

Let’s see how MSIX can simplify the application deployment by keeping together the 16-bit emulator and VB3 application in a single MSIX installation file. The installation will be reduced to a single click action that will install the App in less than 10 seconds.

 

At the same time MSIX will provide a better user experience, allowing users or other apps to call the application executable, in this case, VB.EXE without having to specify the otvdm emulator. This is possible, because once packaged, the App will be access to the UWP manifest that allows us to create an execution alias.

 

MSIX Packaging Tool

The first step is to download and install the MSIX Packaging Tool, that is free and available on Microsoft Store, to allow us to package our App:

 

https://www.microsoft.com/store/productId/9N5LW3JBCXKF

 

mpt store.png

 

 

Before launching the MSIX Packaging Tool, move the emulator and VB folders to another folder, like C:\setup\:

 

setup folder.png

 

This step is need, as MSIX Packaging Tool (MPT) will monitor the changes made on the computer environment. So, as we already have VB3 installed and we don't want to install it again, I will just copy these two folders to their final destinations at the moment that the MPT will be monitoring the modifications.

 

Once installed, open the MSIX Packaging Tool and click on Application package to create a new package for the application:

 

mpt1.png

 

The MSIX Packaging Tool will monitor the changes made on the environment. To perform the packaging, it is possible to use a virtual machine or the physical machine itself to install the application.

 

The best scenario is to use a virtual machine allowing you to reproduce the same process if necessary. It is important that the machine used to install the application does not contain the applications and their previously installed components.

 

Choose the desired scenario and click the Next button:

 

mpt1a.png

 

 

In this step, the tool will verify that the MSIX Packaging Tool Driver is installed and will disable Windows Update to decrease the number of changes to the operating system:

 

mpt2a.png

 

 

Click on the Next button.

 

Only MSIX packages signed with a valid certificate can be installed on Windows 10 machines.

You can create a self-signed certificate for testing purposes, using the following PowerShell command:

 

 

 

 

function CreateCertificate($name, $path)
{

    Set-Location Cert:\LocalMachine\My
    
    New-SelfSignedCertificate -Type Custom -Subject "CN=$name" -KeyUsage DigitalSignature -FriendlyName $name -CertStoreLocation "Cert:\LocalMachine\My"

    $cert = Get-ChildItem "Cert:\LocalMachine\My" | Where Subject -eq "CN=$name"

    $pwd = ConvertTo-SecureString -String DefineTheCertificatePasswordHere@2020 -Force -AsPlainText 

    Export-PfxCertificate -cert $cert.Thumbprint -FilePath "$path.pfx" -Password $pwd
    
    Export-Certificate -Cert $cert -FilePath "$path.cer"
     
    Move-Item -Path $cert.PSPath -Destination "Cert:\LocalMachine\TrustedPeople" 

}

CreateCertificate "luisdem" "cert" 

 

 

 

 

To execute the command, open PowerShell_ISE.exe and press F5. The command creates the test certificate and copies it to the Trusted People folder.

 

It is important to notice that this test certificate should only be used to approve the application in a test environment. To distribute the application.

 

Now, that we have a certificate, we can inform the certificate to have the final MSIX package file automatically signed. It is not necessary to provide the installer file, as the tool monitors all changes made to the operating system.

 

mpt2.png

 

Click on the Next button.

 

In this step, it is necessary to provide information such as the name of the package, the description that will be displayed to the user during installation, the name of the supplier (must be the same as the certificate) and the version number. Fill in the requested information:

 

mpt3.png

 

Click on the Next button.

 

Is in this step that we need to install the application.

 

mpt5.png

 

As we already have the VB3 installed, this is the moment to moving back the emulator and VB3 folders to the drive C root:

emulator and vb3 folders.png

 

Click on the Next button only after completing the application installation and all settings.

 

On the next screen it is necessary to define which applications will be visible in the start menu.

As VB3 is a 16-bit application that depends on the 16-bit emulator, select only the otvdm.exe, as follows:

 

mpt6.png

 

Notice that is not possible to provide the arguments for the otvdm.exe, i.e.,  C:\VB\VB.EXE. For now, we can ignore the arguments as we are fix that later.

 

Follows the expected result so far:

 

mpt7.png

 

Click on the Next button.

 

The following screen is displayed at the end of the installation and asks for confirmation if the monitoring can be ended:

 

mpt7 antes.png

 

Click the Next button, as the application does not install any services:

 

mpt8.png

 

At this point, it is necessary to inform where the package will be generated, as well as it is possible to edit the package before saving it.

 

Click on the Package editor button to check the package structure, as follows:

 

mpt9.png

 

Click on Open file to check how the manifest was generated:

 

mpt9a.png

 

It is possible to edit the manifest information, such as processor architecture, application description, minimum supported version of Windows 10 and others.

 

Change the ProcessorArchitecture to “x86”, the DisplayName and Description attributes to “Microsoft Visual Basic 3.0”:

 

manifest1.png

 

Notice that the Executable attribute doesn’t have the C:\otvdm-master-1846 path, but instead it has the value VFS\AppVPackageDrive\otvdm-master-1846. The AppVPackageDrive is the folder inside the package that corresponds to the drive C root. The application will look for the file on C:\otvdm-master-1846 but it will be redirected to the folder inside the package (VFS\AppVPackageDrive\otvdm-master-1846).

 

The only problem here, is that is no possible to pass arguments in this manifest file. So, we will need to use Package Support Framework (PSF) to fix that.

 

For now, just change the Executable value path to “PsfLauncher32.exe” that is part of the PSF.

 

manifest2.png

 

We will now create an execution alias to allow launching the application by typing or calling the VB.EXE command from anywhere. To do this, add the following lines just below the line </uap:VisualElements>:

 

 

 

<Extensions>
        <uap3:Extension Category="windows.appExecutionAlias" 
                        Executable="PsfLauncher32.exe"
                        EntryPoint="Windows.FullTrustApplication">
          <uap3:AppExecutionAlias>
            <desktop:ExecutionAlias Alias="VB.EXE" />
          </uap3:AppExecutionAlias>
        </uap3:Extension>
 </Extensions>

 

 

 

Follows how the manifest file must be defined:

 

manifest3.png

 

Save and close the manifest (Notepad file) to unblock the MSIX Packaging Tool editor screen.

 

Click on Package files and check if all the files and directories listed are used by the application.

Remove unnecessary files or directories to reduce the package size:

 

mpt9b.png

 

It is at this step that we need to add the Package Support Framework files, to allow the PsfLauncher32.exe calling the emulator passing the arguments.

 

To proceed, download the PSF files (PSFBinaries.zip) available on GitHub:

 

github.png

Releases · microsoft/MSIX-PackageSupportFramework (github.com)

 

psf files.png

 

And extract the contents to a folder of your preference. I will extract to C:\PSF:

 

PSF2.png

 

In the same folder, create a config.json file with the following content:

 

 

 

{
   "applications": [
    {
      "id": "OTVDM",
      "executable": "VFS/AppVPackageDrive/otvdm-master-1846/otvdmw.exe",
      "arguments": "AppVPackageDrive/VB/VB.EXE",
      "workingDirectory": "VFS"
    }
  ]
}

 

 

 

The id corresponds to the Application Id defined in the application manifest, the executable contains the emulator path inside the package and the arguments the VB3 path inside the package.

 

Switch back to MSIX Packaging Tool. In the Package file tab, right click on Package folder and click on

 

Add file from the context menu:

 

mpt10.png

 

Add all the files that finish with 32 and the config.json files to the project:

 

mpt11.png

 

Click on the Create button to generate the package and inform where the file should be generated.

 

The following screen will display where the MSIX file was generated as well as the log file:

 

mpt12.png

 

Install the Visual Basic 3 packaged with MSIX

 

Double-click the package to install the application:

 

install.png

 

You can now launch the application directly from Start menu or typing vb.exe in a prompt command:

 

final.png

 

 

This solution is compatible with MSIX App Attach for Windows Virtual Desktop on-premises or on Microsoft Azure.

 

WVD.jpg

 

 

I hope you like it!!!

 

 

20 Comments
Version history
Last update:
‎Sep 16 2020 05:07 PM
Updated by: