2 minute read

Introduction

Manually installing a Chrome extension outside the Chrome Web Store can be cumbersome due to Chrome’s restrictions on .crx installations. This article introduces a tool that automates the installation process by leveraging Python and Windows Registry modifications. With this approach, users can install a Chrome extension with a single click.

What is the tool?

This tool streamlines the extension installation process by automating the following steps:

  1. Extracting CRX extension files to a local directory.
  2. Modifying Windows Registry to register the extension.
  3. Restarting Chrome to enable the extension automatically.
  4. Packaging the script into an EXE for easy distribution and installation.

By using this tool, you eliminate the need for manual CRX file handling and simplify the deployment of internal Chrome extensions.

Implementation

The following Python script automates the installation process:

import os
import zipfile
import shutil
import winreg
import subprocess

EXTENSION_ID = "abcdefghijklmnoabcdefghijklmno"
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
CRX_PATH = os.path.join(BASE_DIR, "my_extension.crx")
EXTENSION_PATH = os.path.join(BASE_DIR, "chrome_extension")

def extract_crx():
    if not os.path.exists(EXTENSION_PATH):
        os.makedirs(EXTENSION_PATH)
    with zipfile.ZipFile(CRX_PATH, 'r') as zip_ref:
        zip_ref.extractall(EXTENSION_PATH)
    print(f"Extension extracted to: {EXTENSION_PATH}")

def add_extension_to_registry():
    key_path = fr"Software\\Google\\Chrome\\Extensions\\{EXTENSION_ID}"
    try:
        key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, key_path)
        winreg.SetValueEx(key, "path", 0, winreg.REG_SZ, EXTENSION_PATH)
        winreg.SetValueEx(key, "version", 0, winreg.REG_SZ, "1.0")
        winreg.CloseKey(key)
        print(f"Registry updated: {key_path}")
    except Exception as e:
        print(f"Failed to modify registry: {e}")

def restart_chrome():
    try:
        print("Closing Chrome...")
        subprocess.call("taskkill /IM chrome.exe /F", shell=True)
        print("Chrome closed.")
    except Exception as e:
        print(f"Failed to close Chrome: {e}")

def start_chrome():
    chrome_path = r"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
    if os.path.exists(chrome_path):
        subprocess.Popen([chrome_path], shell=True)
        print("Chrome restarted.")
    else:
        print("Chrome not found. Please open it manually.")

if __name__ == "__main__":
    extract_crx()
    add_extension_to_registry()
    restart_chrome()
    start_chrome()
    print("Extension installed successfully!")

Packaging the Tool

To distribute the installer as an .exe file, use PyInstaller:

pyinstaller --onefile --noconsole --uac-admin install_plugin.py

Explanation of Arguments:

  • --onefile → Creates a single .exe file.
  • --noconsole → Hides the console window.
  • --uac-admin → Requests administrator privileges (required for modifying the Windows Registry).

Once built, the final executable file will be available in the dist/ directory as install_plugin.exe.

How It Works

  1. The user runs the executable.
  2. The script extracts the CRX to a local directory.
  3. The Windows Registry is updated to register the extension.
  4. Chrome is restarted automatically.
  5. The extension is installed and enabled.

No manual installation required!
No need to drag and drop the CRX file!
Ideal for enterprise or internal plugin deployment!

Conclusion

This tool offers an efficient way to install Chrome extensions without user intervention. By integrating Python scripting, Windows Registry modifications, and PyInstaller, we achieve a seamless experience for users and IT administrators.

This solution is particularly useful for internal tools, enterprise deployments, and custom Chrome extensions that are not available in the Chrome Web Store. Now, users can install your extension effortlessly!