How MSIX is great for simplify deployment for Visual Basic 6.0 applications
Published Feb 02 2022 11:02 AM 5,104 Views
Microsoft

logo.png

 

I wrote this post as there are many companies that still have VB6 applications running in their environments.

 

Some of the applications no longer have the source code, but are still in use. Others are constantly updated. Most of the time, we are talking about critical applications, with complex installation process that requires administrative credentials to register their components (DLLs and OCXs).

 

Regardless of the application scenario, packaging these applications via MSIX can help developer to simplify, reduce the installation complexity, remove administrative privileges or even enable automatic updates via AppInstaller.

 

MSIX is a Windows app package format that provides a modern packaging experience to all Windows apps. The MSIX package format preserves the functionality of existing app packages and/or install files in addition to enabling new, modern packaging and deployment features to Win32, WPF, and Windows Forms apps.

 

VB6 Virtual Registry Tool

 

This is a very specific project created to assist developers who want to publish their Visual Basic 6.0 applications which still demand periodic updates/implementations, through the MSIX format.

 

This project helps developers to automate the Visual Basic 6.0 packaging by generating a virtual registry file to be added on the VB6 MSIX package with the components (OCXs and DLLs) used by the VB6 application.


Download

 

VB6 Virtual Registry tool is available at:

 

store.png

 

 

git.png

 

 

  • winget

winget.png

 

 

Purpose

 

Some companies have Visual Basic 6.0 applications working well and that don't require modifications. Some of them no longer have the source code of those VB6 applications. For this scenario, the MSIX Packaging Tool is very effective for packaging the VB6 application to the MSIX format which simplifies the installation of those applications by removing the need for administrative rights for installing or registering components.

 

But there are also companies that still have applications developed in Visual Basic 6.0 that are often updated. Unlike other applications, when a VB6 application is modified, in certain situations, the CLSID of its components can be changed during the new build. For this specific scenario, due to the amount of builds and deployments, having to manually perform the entire packaging process to ensure that the virtual registry keys are updated is time consuming.

 

The tool VB6RegistryTool creates the virtual registry of the application components through a single command line, allowing to automate and simplify the packaging of VB6 applications for MSIX.

 

How to generate the virtual registry for MSIX package.

 

Demo application.

 

Let's use the following VB6 Project1, that is available in this repo, as an example of a VB6 application.

 

vb6 project.png

 

 

Create the package structure.

 

To package this project to MSIX, it will be necessary to create a folder with the following structure:

 

folderstructure.png

 

The Assets folder contains the application images like default tile and logo images.

 

assetsfolder.png

 

You can easily generate the images for you application through the PWA Builder Image Generator

 

pwabuilder.png

 

The application and its dependencies can be published in any folder inside the package. But for the case of components that should be installed in the known Windows folders, it is possible to use the special folder called VFS, acronym for Virtual File System, that contains the corresponding folders for the Windows' well-known folders (System32, Program Files, etc). This is great for applications that expects files in the original path outside the package.

 

For example, the Project1 application requires the C:\Windows\System32\RICHTX32.OCX.

 

richtxt32.png

 

A traditional installer would copy the OCX to C:\Windows\System32 and register the same. Through MSIX, it is possible to add the same inside the package through the corresponding folder VFS\SystemX86.

 

The same is valid for the application executable. For our demo application, a traditional installer would install the application executable on C:\Program Files (x86)\MyApp.

 

Follows the content of the ProgramFilesX86 folder:

 

programfilesx86folder.png

 

Because the myfile.txt file is inside the special folder VFS\ProgramFilesX86, during runtime Windows will redirect the application read attempt from C:\Program Files (x86)\MyApp\myfile.txt to the file inside the package. For example, in the next image it is possible to see that the myfile.txt path is hard coded to C:\Program Files (x86)\MyApp\myfile.txt.

 

sourcecode.png

 

During runtime, the app can successfully read the myfile.txt located inside the package (VFS\ProgramFilesX86), even that the path is pointing to C:\Program Files (x86)\MyApp\myfile.txt.

 

project1running.png

 

The other special package folder is the VFS\SystemX86 which refers to its native counterpart C:\Windows\System32. For this sample, this folder contains the RICHTX32.OCX component used by Project1 application.

 

systemx86.png

 

The last file available in the application package folder is the AppxManifest.xml that is the application manifest that contains the elements and attributes that the MSIX application needs.

 

folderstructure.png

 

Here is the application manifest content:

 

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" 
         xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" 
         xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10" 
         xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 
         xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10" 
         IgnorableNamespaces="uap uap10 rescap com">
 
  <Identity Name="VB6Sample" Publisher="CN=Vb6VirtualRegistry" Version="1.0.0.0" ProcessorArchitecture="x86" />
  
  <Properties>
    <DisplayName>VB6 Sample</DisplayName>
    <PublisherDisplayName>AppConsult</PublisherDisplayName>
    <Description>VB6 Sample</Description>
    <Logo>Assets\StoreLogo.png</Logo>
    <uap10:PackageIntegrity>
      <uap10:Content Enforcement="on" />
    </uap10:PackageIntegrity>
  </Properties>
  
  <Resources>
    <Resource Language="en-us" />
  </Resources>
  
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.1" />
  </Dependencies>
  <Applications>

    <Application Id="App" Executable="VFS\ProgramFilesX86\MyApp\Project1.exe" 
                          EntryPoint="Windows.FullTrustApplication">
        
      <uap:VisualElements BackgroundColor="transparent" DisplayName="VB6 Sample" 
                          Square150x150Logo="Assets\VBSix-Square150x150Logo.png" 
                          Square44x44Logo="Assets\VBSix-Square44x44Logo.png"
                          Description="VB6 Sample">
          
        <uap:DefaultTile  Wide310x150Logo="Assets\VBSix-Wide310x150Logo.png" 
                          Square310x310Logo="Assets\VBSix-Square310x310Logo.png" 
                          Square71x71Logo="Assets\VBSix-Square71x71Logo.png"/>
      </uap:VisualElements>
      
    </Application>
     </Applications>
  
<Capabilities>
  <rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>

 

If we just try to package and install the Project1 to the MSIX format right now, the application will throw the following an exception during the initialization because the RICHTX32.OCX is not registered:

 

notRegistered.png

 

As we want to deploy everything inside the MSIX package (files and registry keys), we need to create the virtual registry (registry.dat file) which serves as the logical equivalent of HKLM\Software in the real registry. At runtime, this virtual registry merges the contents of this hive into the native system hive to provide a singular view of both.

 

 

VB6VirtualRegistry.

 

This is the moment where we can use the VB6 Virtual Registry tool to create the virtual registry. The tool will register the component in the physical machine to next export the registry to the virtual registry.dat.

 

The tool is register the component and export the keys to the registry.dat file. As I don't want to have this component registered on my production machine, i.e., to not compromise my tests, since this file will be deployed inside the MSIX package, I will use a VM to run the following command that needs to run elevated (as admin):

 

Vb6VirtualRegistry.exe regsvr32 c:\github\Vb6VirtualRegistry\Sample\unpackaged\VFS c:\github\Vb6VirtualRegistry\Sample\unpackaged\registry.dat

 

Follows the expected result:

 

registryresult.png

 

The file needs to be inside the package root:

 

registryfile.png

 

 

Packaging the directory to MSIX

Now that we have all the files needed (application manifest file, assets, applications files and virtual registry), we can use the following command to package the entire folder to MSIX:

 

Vb6VirtualRegistry.exe pack C:\github\Vb6VirtualRegistry\Sample\unpackaged\ C:\github\Vb6VirtualRegistry\Sample\myvb6app.msix

Follows the expected outcome:

 

resultfilesunsigned.png

 

At this moment, it is not possible yet to install the package, once it is not signed with a certificated valid in our environment.

 

untrustedapp.png

 

The next step is creating a self-signed certificate for testing purpose.

 

 

Using PowerShell to create a self-signed certificate

The following script will load the methods that will be used to create a self-signed certificate:

 


# it loads the methods defined on msixFunctions.ps1
. "C:\github\Vb6VirtualRegistry\Scripts\msixFunctions.ps1"

# it creates a self-signed certificate for CN=VB6VirtualRegistry 
# and it installs the certificate on Local Machine \ Trusted People
# notice that the name must be the same defined on the app manifest Publisher="CN=Vb6VirtualRegistry" 
CreateCertificate "Vb6VirtualRegistry" "C:\github\Vb6VirtualRegistry\Scripts\Sample"

It is important to notice that the certificate publisher, in this case CN=VB6VirtualRegistry, must be the same of the application manifest file (appxmanifest.xml).

 

This PowerShell script is available on GitHub and, it needs to run as elevated (as admin), as it is creating the self-signing certificate and installing the public certificate to the Trusted People folder in the local machine. That step is needed since we are using a self-signed certificate.

 

Signing the MSIX file

Use the following command to sign your directory to MSIX:

 

Vb6VirtualRegistry.exe sign c:\github\Vb6VirtualRegistry\Sample\myvb6app.msix C:\github\Vb6VirtualRegistry\Scripts\Sample\VB6VirtualRegistry.pfx

 

Follows the result files:

 

resultfiles.png

 

 

Install the application.

Now we can install our package application by double-clicking on the myvb6app.msix:

 

msixInstallUI.png

 

Follows the application running as MSIX:

 

vb6MSIX.png

 

Once we are running as MSIX, we don't need admin privileges anymore to install the application, once the application's components are now inside the virtual registry of the package.

 

 

Unpack the MSIX file

Now that we have packaged our application, in case we need to update any information, it is possible to edit the MSIX file through the following command:

 

Vb6VirtualRegistry.exe unpack c:\github\Vb6VirtualRegistry\Sample\myvb6app.msix C:\github\Vb6VirtualRegistry\Scripts\Sample\unpack

 

 

Once you have unpacked it, you can now modify the files, images or regenerate the virtual registry.

 

 

2 Comments
Co-Authors
Version history
Last update:
‎Feb 02 2022 04:17 PM
Updated by: