1. 使用node.js模块

在渲染进程中可以使用node.js模块来获取exe路径:

const path = require('path');
const exePath = path.dirname(process.execPath);
console.log(exePath);
  1. 使用remote模块

在渲染进程中可以使用remote模块来获取主进程的信息,从而获取exe路径:

const { remote } = require('electron');
const exePath = remote.app.getPath('exe');
console.log(exePath);
  1. 使用ipcRenderer模块

在渲染进程中可以使用ipcRenderer模块向主进程发送消息,并从主进程接收信息,从而获取exe路径:

在主进程中,监听获取exe路径的请求:

const { ipcMain } = require('electron');
ipcMain.on('get-exe-path', (event) => {
  event.reply('get-exe-path-reply', process.execPath);
});

在渲染进程中,向主进程发送获取exe路径请求,并监听主进程回复:

const { ipcRenderer } = require('electron');
ipcRenderer.send('get-exe-path');
ipcRenderer.on('get-exe-path-reply', (event, exePath) => {
  console.log(exePath);
});
``
electron 在渲染进程中获取exe路径 多种方式

原文地址: https://www.cveoy.top/t/topic/fiKR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录