You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron Forge 6技术咨询:能否生成uninst.exe实现无需控制面板卸载应用?及使用squirrel-windows生成器创建uninst.exe的方法

关于Electron Forge 6生成uninst.exe的问题

能不能生成uninst.exe?

当然可以!Electron Forge 6搭配squirrel-windows生成器时,默认就会在应用的安装目录里生成uninst.exe,用户直接运行这个文件就能卸载应用,完全不需要通过控制面板操作。

怎么配置和使用?

结合你提供的现有配置,我给你梳理下关键要点:

1. 修正squirrel-windows配置细节

你的当前配置已经包含了squirrel-windows生成器,但有个小细节需要调整:noMsi参数应该是布尔值,而非字符串"false"。修改后的完整配置如下:

"config": {
  "forge": {
    "packagerConfig": {
      "icon": "./static/img/app.ico",
      "asar": true
    },
    "makers": [
      {
        "name": "@electron-forge/maker-squirrel",
        "config": {
          "name": "voerkaintercomclient",
          "setupExe": "myApp.exe",
          "setupIcon": "./static/img/app.ico",
          "copyright": "myApp",
          "noMsi": false // 改为布尔值,默认也是false,明确写出更清晰
        }
      },
      {
        "name": "@electron-forge/maker-zip",
        "platforms": [ "darwin" ]
      },
      {
        "name": "@electron-forge/maker-deb",
        "config": {}
      },
      {
        "name": "@electron-forge/maker-rpm",
        "config": {}
      }
    ]
  }
}

2. 找到uninst.exe的默认位置

打包安装后,uninst.exe会存放在应用的安装根目录,默认路径为:
C:\Users\<你的用户名>\AppData\Local\<你的应用名>\uninst.exe
(其中<你的应用名>对应配置里的name字段:voerkaintercomclient)

3. 在应用内添加卸载入口(可选但推荐)

为了让用户更便捷地卸载,可以在应用里添加卸载按钮或菜单选项,通过Electron API调用uninst.exe:

在主进程(比如main.js)中添加如下代码:

const { app, shell, Menu } = require('electron');
const path = require('path');

// 定义卸载函数
function handleUninstall() {
  // 拼接uninst.exe的路径
  const uninstallerPath = path.join(app.getPath('userData'), '../', 'uninst.exe');
  // 打开卸载程序
  shell.openPath(uninstallerPath).catch(err => {
    console.error('打开卸载程序失败:', err);
  });
  // 退出当前应用
  app.quit();
}

// 示例:在应用菜单中添加卸载选项
const template = [
  {
    label: '帮助',
    submenu: [
      {
        label: '卸载应用',
        click: handleUninstall
      }
    ]
  }
];

const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);

4. 打包测试

运行electron-forge make命令打包Windows应用,安装后即可在对应目录找到uninst.exe,也可以直接通过应用内的卸载入口测试功能。

内容的提问来源于stack exchange,提问作者radiorz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 06:51:02