Run local *.exe file using Js - Electron

Hi there, I am pretty new to Electron and I was wondering on how to run a local *.exe file. I am developing a game launcher to hold all the games I make. I want to have the *.exe file within the downloaded files and that I can click a button on a page to run the *.exe.

The struggles I’m finding hard to solve is

  • To launch the *.exe.
  • find the file locally within the installed files rather than hard-coding a directory.

Any help would be great.

Thanks :slightly_smiling_face:

In your main process (where you create the Browser window), export a function such as

export const execFile = (cmd: string, parameters?: readonly string[]) => {
	const childProcesses = require("child_process");
	childProcesses.execFile(cmd, parameters ?? null);

If you’re using commonjs you’ll need to use the module.exports syntax instead.

In your render process, call it via

require("electron").remote.require("./electron").execFile("path/to/exe") // replace the 2nd "electron" with the name of your main process file if needed.