I am using electron app.setLoginItemSettings(settings) to enable my application to autostart at login. This is how I am implementing it:
const executable_path = process.execPath;
const exeName = path.basename(process.execPath);
...
const createWindow = () => {
...
ipcMain.on('close-me', (evt, arg) => {
var boot = settings.get("startatboot");
if (boot) {
app.setLoginItemSettings({
openAtLogin: true,
path: executable_path,
name: exeName,
args: [
'--processStart', `"${exeName}"`,
'--process-start-args'
]
})
} else {
app.setLoginItemSettings({
openAtLogin: false,
openAsHidden: false
});
}
app.quit()
});
...
};
And this result in the following inside the register (Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run)
Test Autorun.exe
for name
C:\Program Files\Test Autorun\Test Autorun.exe --processStart "Test Autorun.exe" --process-start-args
for data
Now inside my package.json
file I defined the following:
{
"name": "apptest",
"productName": "Test Autorun",
"version": "1.0.0",
"description": "Test Autorun",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\"",
"build-installer": "electron-builder"
},
"build": {
"appId": "apptest",
...
Now my problem is that the application is not running on start and I have no idea why this is happening, I tried changing a lot of the values to end up with this register content. All the attempts before were showing as different programs inside windows startup settings
.
I have got to fill what I think is correct data inside the registers but there is something I am missing but I have no idea what it is. Any help would go a long way, thanks.
EDIT:
When I launch the app normally it always asks the user to allow the app with unknown publisher
to make changes to the device. I don't know if that is why the app is not running on start or if the app would run showing the same message awaiting user approval.
EDIT2:
it is adding the register inside the HKEY_CURRENT_USER
and not the HKEY_LOCAL_MACHINE
As I suspected, it was related to the unknown publisher
popup; so, when I edited the registry entry related to UAC
by using the following command line code shown below, the application started on boot.
%windir%\System32\reg.exe ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f