2

To make an installation of opensource software for the Windows platform single click, I am trying to convert the setup.ps1 into a setup.exe file. (To make a powershell script executable in a single (double) click, the user might/is still required perform additional actions). So to do that I downloaded PS2Exe from https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5. After running the following command in the correct folder in powershell:

.\ps2exe.ps1 .\setup.ps1 .\target.exe

The exe is indeed created. But upon inspection I found that the target.exe file is not inspectable with e.g. Winrar, whereas the latest installer of Eclipse, eclipse-inst-win64.exe, is.

Hence my question is: How can I convert the setup.ps1 to a single click setup.exe that is inspectable*/opensource?

*With inspectable, I mean a computer illiterate can still relatively easily see what the original lines of code and files are, e.g. no bytecode/no assembly etc.

Approaches

  1. Thanks to the comments, I learned the reason the eclipse installer that is used as an example, consists of a self extracting zip file. After a short inspection I have not yet found an example of a self extracting zip file that is able to execute a powershell script without requiring user input. Such an example could suggest a feasible solution would be to create a self extracting zip that executes the setup.ps1 but it appears unlikely.
  2. Wix installer has an option to include powershells into an MSI file.

    2.1 I have yet to determine whether it is also able to create a setup.exe file that allows the setup.ps1 to be execute, and whether it can execute the powershell without requiring extra user actions.

    2.2 I have yet to determine whether the setup.exe is (easily) reverse-engineerable, it appears ORCA is able to reverse engineer an MSI installer file, but I am not yet sure whether that qualifies as "Open Source" as it might be possible that different code/file combinations yielded the same MSI.

  3. Based on https://4sysops.com/archives/creating-an-exe-for-your-powershell-scripts-using-winrar/ as suggested in the comments, I created an exe with sfx that unpacks the setup.ps1 file to: E:/some folder with a space/ using comments:
Path="E:\some folder with a space\target/"
SavePath
Setup=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -sta -noexit -noprofile -executionpolicy bypass -file "E:\some folder with a space\target\setup.ps1"
Silent=1
Overwrite=1

without adding an icon. However when the exe is executed it returns:

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.

    lxrun : The term 'lxrun' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
    the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At E:\18-09-19 Document structure\personal\Programming\tools\powershellToExe\target\setup.ps1:1
char:1
    + lxrun /install /y
    + ~~~~~
        + CategoryInfo          : ObjectNotFound: (lxrun:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException ```

Much like powershell is in a different path than the setup.ps1 script that is executed. When I open a powershell via Start>Powershell, enter E:followed by cd "E:\some folder with a space\target" and run./setup.ps1the unpackedsetup.ps1` runs fine. So I checked with command:

[bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")

whether the difference between the powershells was in administrative priviliges, which it was not.

The content of the powershell script is:

lxrun /install /y
lxrun /setdefaultuser testlinuxname /y
lxrun /setdefaultuser root /y
bash -c "echo 'testlinuxname:mypassword' | chpasswd"
bash -c "sudo echo 'testlinuxname ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
wsl sudo apt update
bash -c "echo 'yes' | sudo apt install default-jre"
lxrun /setdefaultuser testlinuxname /y
Read-Host -Prompt "Press Enter to exit"

To investigate the possible reason for the execution difficulties the SFX conversion from ps1 to exe yield, I will include an echo of the current directory in the setup.ps1 to inspect the paths which powershell works in.

4
  • 2
    you can only see the "code" because eclipse-inst-win64.exe is a self extracting zip.
    – Ewan
    Commented Aug 2, 2019 at 10:19
  • @Ewan, thank you. I could not find any examples of a self extracting zip executing a powershell script. I will use your comment to include approaches in my question.
    – a.t.
    Commented Aug 2, 2019 at 10:27
  • 1
    4sysops.com/archives/…
    – Ewan
    Commented Aug 2, 2019 at 10:29
  • 1
    stackoverflow.com/questions/3759456/…
    – Ewan
    Commented Aug 2, 2019 at 10:41

1 Answer 1

2

Credits go to @Jotunn and @Ewan. As listed in the link provided by @Ewan, the answer of @Jotunn provided a solution. Powergui allows conversion of setup.ps1 to setup.exe. The verified steps as described are:

Open your script in the PowerGUI Script Editor > Tools > Compile script.

Then your powershell script gets executed in a Console Window Host if you run it. The compiled setup.exe is still inspectable by for example winrar.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.