3

I have an installation file created by electron-builder and faced issue that can't find a way how to run powershell script after installation.

The idea is to make some changes in windows registry and set permission for application folder.

As far as I understand it should be configured in build section in package.json. In api I found that it is exist afterPack method, but I can't figure it out how to execute powershell file through it.

Thank you.

1
  • 3
    I've removed the powershell tag from your question, even though your question involves powershell it's not a question about powershell. Commented Oct 9, 2018 at 15:42

1 Answer 1

3

First, create an afterPack.js file, containing this code:

exports.default = async function () {
    const { exec } = require('child_process');
    const bat = exec('powershell "& ""path/to/powershell/file.ps1"""');
}

Edit the path to the .ps1 file accordingly. You may need to add a '.\' to the start of the path. The console readout will tell you if you do.

Next, edit your package.json file to include an afterPack parameter in your build settings, like so:

enter image description here

Now when you run your build script, it will run your .ps1 file.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you a lot, this is it.
Is there any way to find out where application was installed to apply permissions to this folder through powershell ?
I'm sure there is. I would look at AfterPackContext and/or BuildResult , particularly the outDir property. How you actually use these interfaces is beyond me. Post another question and I'm sure someone will be able to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.