Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

How to get Electron app to start on system startup? #115

Open
hyperh opened this issue Apr 20, 2016 · 15 comments
Open

How to get Electron app to start on system startup? #115

hyperh opened this issue Apr 20, 2016 · 15 comments

Comments

@hyperh
Copy link

hyperh commented Apr 20, 2016

I'm having some trouble getting my Electron app to start on system startup, does anyone know how this could be done?

Ideally, I could provide users with an ability to toggle this functionality in the Electron main window menu.

@philipgiuliani
Copy link

There is a npm package which works great with electron for that!
https://www.npmjs.com/package/auto-launch

@zeke
Copy link

zeke commented Apr 22, 2016

Yep. auto-launch works like a charm!

@ananyaojha
Copy link

ananyaojha commented Aug 11, 2017

Can you please help me out with step wise commands to create an auto-launch electron app?

I have some way of doing that. Kindly have a look and let me know what to change in this as I'm getting error with npm install electron-prebuilt --save-dev command ?

Please go through this link https://stackoverflow.com/questions/45632502/getting-error-while-executing-npm-install-save-dev-electron-prebuilt?noredirect=1#comment78224205_45632502 to see exactly what is happening when I run this command

STEPS :

mkdir dirname
cd dirname
npm init
npm install electron-prebuilt --save-dev
Create index.js
npm install electron-packager --save-dev
npm start
npm run build OR electron-packager . --all

Thank you for your support in advance.

@zeke
Copy link

zeke commented Aug 11, 2017

Since this issue was opened, an API has been added to Electron for starting the app at login: https://electron.atom.io/docs/api/app/#appsetloginitemsettingssettings-macos-windows

@luoboding
Copy link

luoboding commented Dec 8, 2017

@zeke thank you, i tried it like this,

const exeName = path.basename(process.execPath);
app.setLoginItemSettings({
openAtLogin: true,
path: process.execPath,
args: [
'--processStart', "${exeName}",
'--process-start-args', "--hidden"
]
});

it works for me on windows. but the demo of this api in doc is not correct, the path should be the folder of your app which you want to auto startup.

@zeke
Copy link

zeke commented Dec 11, 2017

the demo of this api in doc is not correct, the path should be the folder of your app which you want to auto startup.

@luoboding you mean in the electron/electron docs? If so, would you be able to open a pull request that corrects it?

@luoboding
Copy link

sorry @zeke , my mistake, i think i misunderstand 'process, execPath' which means the path of app you are running, not the folder, i test the official demo, it works fine. sorry about that.

@RedDeathAt614
Copy link

Question for Windows (NSIS):

What @luoboding is doing only works for me after I have run the app manually at least once. This means that if I'm using perMachine: true I have to manually open the app once for all users. In our case this means doing this manually for hundreds of users at one of our clients call centers. This is not feasible for us or for our client.

It would seem that all I need to do is to add the app to the Startup menu in the Windows start menu as a part of the installer. Surely this must be possible somehow? Yet has eluded me for some time now. Anybody knows how to pull this off?

@luoboding
Copy link

@RedDeathAt614 i use NSIS to pack my app, app will be opened automatically when installation is finished.

@RedDeathAt614
Copy link

RedDeathAt614 commented Jan 12, 2018

Thanks @luoboding

If anybody's interested I ended up solving it by setting perMachine: true and then include an installer.nsh file in the build directory which looks like this:

 !macro customInstall
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "CortiRespond" "C:\Program Files\Corti\Corti Respond\Corti Respond.exe"
 !macroend

 !macro customUnInstall
   DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "CortiRespond"
 !macroend

Hence just setting a key in the registry database to start the app on login and remove it again when the app is uninstalled. This seems to work nicely.

@zhao2258
Copy link

zhao2258 commented Jul 5, 2018

请问如何禁止让项目在安装的时候自动启动?

@luoboding
Copy link

@zhao2258 you should open a new issue.

@luoboding
Copy link

luoboding commented Jul 10, 2018

@zhao2258 i hope this could help you. https://www.electron.build/configuration/nsis

@jadhavrani123
Copy link

Sir I want to close my developer tool on click cntrl + shift + I

WebPreferences = new WebPreferences
{
DevTools = false
}
I am use this code........but it not work for me

@erickximenes
Copy link

Senhor, quero fechar minha ferramenta de desenvolvedor clicando em cntrl + shift + I

WebPreferences = new WebPreferences
{
DevTools = false
}
Estou usando este código ........ mas não funciona para mim

In the index.js file, comment out this line:
//mainWindow.webContents.openDevTools();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants