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,
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.
- 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.ps1but it appears unlikely.
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.exefile that allows the
setup.ps1to be execute, and whether it can execute the powershell without requiring extra user actions.
2.2 I have yet to determine whether the
setup.exeis (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.
- 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
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
cd "E:\some folder with a space\target" and run./setup.ps1
the unpackedsetup.ps1` runs fine. So I checked with command:
[bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
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
exe yield, I will include an
echo of the current directory in the
setup.ps1 to inspect the paths which powershell works in.