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.
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.
VB6 Virtual Registry tool is available at:
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.
Let's use the following VB6 Project1, that is available in this repo, as an example of a VB6 application.
To package this project to MSIX, it will be necessary to create a folder with the following structure:
The Assets folder contains the application images like default tile and logo images.
You can easily generate the images for you application through the PWA Builder Image Generator
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.
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:
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.
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.
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.
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.
Here is the application manifest content:
<?xml version="1.0" encoding="utf-8"?>
IgnorableNamespaces="uap uap10 rescap com">
<Identity Name="VB6Sample" Publisher="CN=Vb6VirtualRegistry" Version="22.214.171.124" ProcessorArchitecture="x86" />
<uap10:Content Enforcement="on" />
<Resource Language="en-us" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.1" />
<Application Id="App" Executable="VFS\ProgramFilesX86\MyApp\Project1.exe"
<uap:VisualElements BackgroundColor="transparent" DisplayName="VB6 Sample"
<rescap:Capability Name="runFullTrust" />
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:
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.
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:
The file needs to be inside the package root:
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:
At this moment, it is not possible yet to install the package, once it is not signed with a certificated valid in our environment.
The next step is creating a self-signed certificate for testing purpose.
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
# 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.
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:
Now we can install our package application by double-clicking on the myvb6app.msix:
Follows the application running as MSIX:
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.