electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.71k stars 1.74k forks source link

NSIS Installer doesn't launch on Windows 11 when perUser is set by default #8536

Open pnedkovp opened 2 months ago

pnedkovp commented 2 months ago

We have an issue with nsis installer on Windows 11. After the application is build the installer doesn't launch on some machines. We have tried building the application with different attributes and it seems that it has something to do with the perMachine property. These are our production build attributes: "nsis": { "oneClick": false, "allowElevation": true, "perMchine": false, "artifactName": "${productName} ${version}.${ext}" }

If we change to oneClick: true or selectPerMachineByDefault: true then the installer starts successfully but with our current setup (onClick: false, perMachine: false) sometimes it crashes.

The error in the event viewer is this: Faulting module name: System.dll, version: 0.0.0.0, time stamp: 0x5c157efa Exception code: 0xc0000005 Fault offset: 0x00001581 Faulting process id: 0x0xF30 Faulting application start time: 0x0x1DB05CD5454D5C0 Faulting application path: Faulting module path: C:\Users\AppData\Local\Temp\nsmD439.tmp\System.dll Report Id: 0e92fa50-e642-47bd-8aac-4b2d8e89f8f8 Faulting package full name: Faulting package-relative application ID:

mmaietta commented 2 months ago

What sticks out to me is the lack of any name here:

Faulting package full name:
Faulting package-relative application ID:

I found this regarding DEP: https://www.tenforums.com/software-apps/206789-application-stopped-running-i-dont-know-what-else-try-2.html and this regarding the Exception Code: https://answers.microsoft.com/en-us/windows/forum/all/how-do-i-fix-this-exception/33382768-19f5-473f-98a2-07e08194272b

Application Error 0xc0000005 (Access Violation) error is usually caused by your computer not being able to correctly process the files and settings required to run a particular program or installation.

I'm not sure if there's much support I can provide here from a code standpoint though. I'm pretty unfamiliar with windows exceptions.

pnedkovp commented 2 months ago

The reason I turn to you is because the installer fails only with a specific set of attributes and not every time. For me it seems it has something to do with the nsis installer script in the case when the default option is to install for the current user only.

pnedkovp commented 2 months ago

I have already tried turning off security features including DEP but it didn't do the trick. I also found similar resources on the exception code but I am using a fresh installation of Windows 11 which was specifically made to test the issue above and it doesn't seem to have anything to do with corrupted memory or system files. The issue appears sporadically and it could be something related to OS settings but we can't seem to find such.

pnedkovp commented 2 weeks ago

Hello again, I managed to find where the problem occurs. It's on this line of the multiUser.nsh - https://github.com/electron-userland/electron-builder/blob/3d8e402f0ff1930de9c009dd78ee6dd8fe9c6133/packages/app-builder-lib/templates/nsis/multiUser.nsh#L30 When we have a fresh installation it goes into the else statement and one of the System:: calls crashes the installer. What I would like to do is to simply set the $INSTDIR to "$LocalAppData\Programs\${APP_FILENAME}" I am trying to figure out a way to customise the nsis installer using a custom macro but I cannot seem to figure it out.

pnedkovp commented 2 weeks ago

I managed to resolve the problem by using a before-build script which replaces the multiUser.nsh file with a custom one before build.