- 1 year ago
Electronjs - Delete registry entries when uninstalled
To delete registry entries when an Electron application is uninstalled, you can make use of the electron-builder
package, which provides a built-in mechanism for handling cleanup tasks during the uninstallation process.
Here's an example of how you can delete registry entries during uninstallation using electron-builder
:
Install
electron-builder
: Open your project directory in a command prompt or terminal and install theelectron-builder
package as a development dependency:bashnpm install electron-builder --save-dev
Configure the
electron-builder
inpackage.json
: In yourpackage.json
file, add abuild
section with the appropriate configuration forelectron-builder
. Here's a minimal example:json"build": {
"afterAllArtifactBuild": "scripts/cleanup.js"
}
Create a cleanup script: Create a JavaScript file (e.g.,
cleanup.js
) in ascripts
directory under your project's root. This script will contain the logic to delete the necessary registry entries. For example:javascriptconst { execSync } = require('child_process');
try {
// Delete registry entries using the appropriate command or library
execSync('reg delete HKCU\\Software\\YourApp /f');
console.log('Registry entries deleted.');
} catch (error) {
console.error('Error deleting registry entries:', error);
}
Replace
'reg delete HKCU\\Software\\YourApp /f'
with the appropriate command to delete the desired registry entries. You can use thereg
command or any library/package that facilitates registry manipulation.Build and package the Electron application: Use the
electron-builder
command to build and package your Electron application:bashnpx electron-builder --win
This will create a distributable package for Windows, including the cleanup script.
Test the uninstallation process: Install the packaged application on a test system, and then uninstall it using the standard uninstallation procedure. During the uninstallation,
electron-builder
will run the cleanup script, which will delete the specified registry entries.
By following these steps, you can configure electron-builder
to execute a cleanup script during the uninstallation process of your Electron application, allowing you to delete the required registry entries.