[Python] How should I write custom install and uninstall nsis for electron builder?

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    hello, I am building an electron app.

    I need to do 2 things while installing the app

    1.set custom installation path


    here is the the code how I done the first step

    !macro preInit
    SetRegView 64
    WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Windows\BSD"
    WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Windows\BSD"
    SetRegView 32
    WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Windows\BSD"
    WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Windows\BSD"
    !macroend


    And in the package.json build field I write this:

    "nsis": {
    "deleteAppDataOnUninstall": true,
    "oneClick": false,
    "allowElevation": true,
    "installerIcon": "build/icon.ico",
    "uninstallerIcon": "build/icon.ico",
    "installerHeaderIcon": "build/icon.ico",
    "createDesktopShortcut": true,
    "createStartMenuShortcut": true,
    "shortcutName": "BSD",
    "perMachine": true,
    "include": "build/installer.nsh"
    }


    Its working fine

    2.run a command line to install the python


    I dont know how to do the 2 setp which is to install the python if not installed.
    which mean I need to run python -V to check the response is null or not
    and then based on the response to consider install the python or not here is the command line to install python pathOfpython.exe /repair /quiet InstallAllUsers=1 PrependPath=1

    And I need to do 2 things on uninstalling

    1.remove the folder C:\Windows\BSD as administrator which is my app installaing path


    In my understanding it will done if I spcified the installation path which is C:\Windows\BSD but when I uninstall my app the installation folder did not removed I dont know what is going on.

    2.run a command line schtasks /Delete /TN ${taskName} -F as administrator


    This line of code will remove the task which created by my app
    This is simple if I know how to run a command line as administrator from nsh file. But currently I dont know how to do that

    Thanks!!!

    Updates


    I done the 3 steps of the 4 steps here is the code

    !macro preInit
    SetRegView 64
    WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Windows\BSD"
    WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Windows\BSD"
    SetRegView 32
    WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Windows\BSD"
    WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Windows\BSD"
    !macroend

    #This one not working
    !macro customInstall
    File {$SOURCEPATH}\\python-3.11.0.exe
    ExecWait '$PLUGINSDIR\python-3.11.0.exe /repair /quiet InstallAllUsers=1 PrependPath=1'
    !macroend

    !macro customUnInstall
    ExecWait "schtasks /Delete /TN BSD-TASK -F"
    ExecWait "del /f C:\Windows\BSD"
    !macroend


    But I stucked at at installing the python the error says thereis no file called python-3.11.0.exe
    Here is my build folder
    [​IMG]

    Here is the error:

    Processing script file: "<stdin>" (UTF8)
















    Error output:
    File: "{$SOURCEPATH}\\python-3.11.0.exe" -> no files found.
    Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
    /oname=outfile one_file_only)
    Error in macro customInstall on macroline 1
    !include: error in script: "installSection.nsh" on line 79
    Error in script "<stdin>" on line 192 -- aborting creation process
    at ChildProcess.<anonymous> (C:\Users\OnTheRoad\Desktop\learningCodes\react\child-controller\node_modules\builder-util\src\util.ts:250:14)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.cp.emit (C:\Users\OnTheRoad\Desktop\learningCodes\react\child-controller\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1100:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)

    Continue reading...

Compartilhe esta Página