Run Electron applications with admin privileges in Windows

Electron Builder + Task Scheduler = Run as admin without UAC

Sun, 06 Jan 2019

I spent a couple of days figuring out how I can get my application to run on computers in my domain without sending UAC prompts to users. I was finally able to figure out yesterday.

Disclaimer - I used Electron React Boilerplate to bootstrap my project and will be writting this out in reference to that.

Electron Builder Settings

My application is meant to run only on windows machines so I removed the dmg and linux fields from my object in package.json. If you’re application is meant to be ran cross platform, you can leave those fields as they are. Here is the code for the build field

  "build": {
    "productName": "Product Name",
    "appId": "org.develar.ProductName",
    "files": [
      "app/dist/",
      "app/app.html",
      "app/main.prod.js",
      "app/main.prod.js.map",
      "package.json"
    ],
    "win": {
      "target": "nsis",
      "requestedExecutionLevel": "requireAdministrator"
    },
    "nsis": {
      "guid": "eb1a0fbb-fc70-428e-97f1-fa7080894806",
      "oneClick": true,
      "perMachine": true
    },
  }

Quick explanation of the fields that I changed.

  • productName - NAme of your app, can be anything and include spaces
  • appId - identification string for your app, doesn’t matter too much unless you plan on publishing to the windows/mac store
  • requestedExecutionLevel - set to admin in order to get access to administrator type functions on the system
  • guid - identifier for your application, should be unique. I used this website website to generate a random guid.
  • oneClick - allows for silent deployments of your application.
  • perMachine - installs the application for all users on the computer
Buy Me A CoffeeDigitalOcean Referral Badge
Loading...
Edward Beazer

Edward Beazer - I just like to build shit. Sometimes I get stuck for hours, even days while trying to figure out how to solve an issue or implement a new feature. Hope my tips and tutorials can save you some time.

DigitalOcean Referral Badge