4

I am writing an electron app that I need to run with admin access (like sudo).I haven't created any installer for that app.

I know that I can write sudo electron . in linux to start my app as root but what about windows? Is there any similar command?

Manos Kounelakis
  • 2,848
  • 5
  • 31
  • 55
  • right-click > run as administrator? –  Aug 01 '17 at 21:41
  • 2
    @Thebluefish I haven't packaged it as an app it's just an electron project there is no executable you just open a terminal to the project folder and type `electron .` – Manos Kounelakis Aug 01 '17 at 23:25

2 Answers2

3

You can open Command Prompt as Administrator and then run the app via electron .

Sean
  • 1,444
  • 1
  • 11
  • 21
1

If you're using electron builder, you can make the build that will run with admin rights by adding this in your builder config:

win: {
  requestedExecutionLevel: 'requireAdministrator',
}

If you can find the docs here

Note

Keep in mind, if you run an app with admin rights the drag & drop feature will not work

So instead of launching the whole app with admin rights, you should create a separate child process and then run that process with admin rights

AlekseyHoffman
  • 2,438
  • 1
  • 8
  • 31
  • Hello . Thanks for your answer . Unfortunately I no longer have the case for using windows and cannot test your answer. Could you elaborate a little bit on why won't the drag and drop feature won't work? Is there any documentation for me to read more? – Manos Kounelakis Jul 29 '22 at 07:59
  • On Windows (and probably other OS), any process launched with admin rights cannot interact with other processes (apps). It's not Electron specific. You can try it with any default app like Paint, for example, you won't be able to drag & drop an image on it – AlekseyHoffman Jul 29 '22 at 08:06