PS2EXE-GUI: "Convert" PowerShell Scripts to EXE Files with GUI

Overworking of the great script of Ingo Karstein with GUI support. The GUI output and input is activated with one switch, real windows executables are generated. With Powershell 5.x support and graphical front end.

PS2EXE-GUI.zip
 
 
 
 
 
4.7 Star
(35)
33,463 times
Add to favorites
7/1/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Run As Admin
    2 Posts | Last post May 08, 2019
    • Having problem running my .exe as Admin.
      I can right click the .exe and run as admin and it opens just fine.
      However in my windows form I have various buttons configured to do different things that need admin rights.  Any button I click on has no admin rights even though I do a run as admin to launch it.  Suggestions??
    • Hello BFrisan,
      
      can you tell what kind of actions are invoked when a button is pressed in your application and how do you invoke them?
      
      Greetings
      
      Markus
  • Overwriting ps1 files
    6 Posts | Last post April 29, 2019
    • I was testing this script earlier today and it works great - thanks! I did make a mistake by setting my output file to be the ps1 script I wrote. Unfortunately, ps2exe overwrote my ps1 script, but luckily I had backups and was able to restore it.
      
      I recommend adding the following lines to prevent this:
      
      if ($outputFile -like "*.ps1")
      {
          Write-Host "Input file cannot be a ps1 file."
          exit -1
      }
    • Had a typo in there! The Write-Host line should say "Output file cannot be a ps1 file.".
    • Hello sbirdsill,
      
      for this reason there is the check:
      
      if ($inputFile -eq $outputFile)
      {
      	Write-Host "Input file is identical to output file!"
      	exit -1
      }
      
      in PS2EXE. This should prevent what you describe, are you using the latest version?
      
      Greetings
      
      Markus
    • That would only work if your input file is verbatim to your output file. In my case, I did something like -inputfile test.exe -outputfile test.ps1 (I already had test.exe in the folder from a previous attempt).
      
      But I found out that you can "decompile" it by running the exe file with the "extract" flag. So I could do "./test.exe -extract:test.ps1" and that would extract the PS1 script out of the exe.
      
      Pretty neat! Luckily I was just experimenting with it, so it wasn't a big concern in the first place.
    • Hello sbirdsill,
      
      I ask for your understanding that PS2EXE cannot intercept every wrong parameter. But the next version will check if the output parameter is an executable file. This will also solve your issue.
      
      Greetings
      
      Markus
    • Hello sbirdsill,
      
      the new version v0.5.0.15 of PS2EXE I released today checks for the output file's extension (.exe or .com). This should solve your issue.
      
      Greetings
      
      Markus
  • Progress Bar Icon
    3 Posts | Last post April 29, 2019
    • I notice the progress bar message box will not display the Icon specified on the task bar.
    • Hello jackofalltech,
      
      there is no icon in the progress bar or input box window, since there is no easy way to combine it with the application's icon.
      
      Simply it is to expensive to provide the code for this (icon file had to be read at compile time and converted to a binary variable that is converted back from variable to icon at runtime of the window).
      
      Greetings
      
      Markus
    • Hello jackofalltech,
      
      I investigated your request further and learned that it is quite easy to place the application's icon in a custom form. The new version v0.5.0.15 of PS2EXE I released today has this feature.
      
      Greetings
      
      Markus
  • Add dependencies to compiled script
    2 Posts | Last post April 28, 2019
    • Would it be possible to add a switch so that required dependencies are compiled along with the main scrip? This would let me compile into a single .exe rather than having to place the script/file dependencies in the same directory as the exe and/or code the logic to specify the location.
      
      e.g. A script which loads file paths from a csv, or calls another script could be complied with "-addfile ./filename.ps1 ./filename2.csv and when these files are required, they can be called from the script without a path.
      
      
      This facility is available in the now-discontinued PowerGUI and still works in that for now, but I anticipate this will no longer work at some point.
    • Hello Scepticyn,
      
      I'm sorry to say that I do not see a way to fulfill your wish. Unlike most of the other PS1 compilers PS2EXE does not create a self extracting archive that unpacks the script and accompanying files to the temporary directory but creates a C# standalone application (a PowerShell host) containing the script.
      
      Maybe a self extracting utility is rather what you need?
      
      Greetings
      
      Markus
      
  • Exiting the environment
    2 Posts | Last post April 11, 2019
    • For some reason, when loading the exe with an external program the following code loop causes the script in executable format to lock. I'm not sure if this is a bug, or the Powershell script itself, but if i remove this logic, the script runs fine. I'm calling the PS.exe from within another program.
      
       while (true)
                 {
                     process.WaitForExit(_waitForMS);
                     if (process.HasExited)
                     {
                         break;
                     }
      
                 }
      
      
      any ideas here?
    • Hello Zesty01,
      
      there is not enough Information in your question to answer it.
      
      - how did you obtain the process object?
      - what is the value of _waitForMS?
      - is your script compiled to console or noconsole app?
      
      Greetings
      
      Markus
  • BitsTransfer and runtime20
    3 Posts | Last post April 08, 2019
    • Hi Markus, 
      Thanks for the great tool. I am quite new t powershell programming but learnt a great deal working with this code and trying to convert a mini project to exe.
      
      In my code, I am importing BitsTransfer to download some microsoft updates and since I am deploying the code to be compatible with powershell 2 (applicable tool to Windows 7,8, and 10), I am running with runtime20 flag.
      
      However in doing so, my EXE runs properly in Windows 7 (powershell 2) while it fails under Windows 10 (powershell 5). The error complains that module cannot be imported because its manifest contains one or more members that are not valid.
      
      I was wondering if this is maybe a bug or I am doing something wrong (quite possible) or maybe not clear on "runtime20" flag? 
      
      Would appreciate your feedback
    • Hello moe01,
      
      this seems to be a problem or a bug with PowerShell V2 on Windows 10.
      
      On your Windows 10 Computer please start your PowerShell manually in Version 2.0 (same as -runtime20) with:
        powershell.exe -Version 2
      and then execute
        Import-Module BitsTransfer
      
      You get the same error. It has nothing to do with PS2EXE. Additionally I found no advice on Google to this.
      
      Sorry for that
      
      Greetings
      
      Markus
      
    • Markus,
      Huh Interesting, I probably should have tried it myself before posting.!
      Thanks a lot for clarification!
      
      Cheers,
      Moe
  • Exiting the environment and PSScriptRoot
    2 Posts | Last post April 05, 2019
    • Hi!
      
      two things: It seems that the variable PSScriptroot as well as the $Myinvocation.mycommand variable do not work properly when using this tool to convert the script to exe.
      
      Any thoughts on how to combat that?
      
      Also,
      It could just be me, but exiting the environment does not deliver the exit code outward.
      
      Thoughts?
    • Hello Zesty01,
      
      see chapter "Remarks" on the "Description" tab for this topic.
      
      Greetings
      
      Markus
  • Compilation limitation?
    3 Posts | Last post April 04, 2019
    • Hello Markus,
      
      I'm getting an compilation error :
      
      Could not create the PowerShell .exe file because of compilation errors. Use -verbose parameter to see details.
      COMMENTAIRES : error CS0013: Erreur inattendue lors de l'écriture des métadonnées dans le fichier 'd:\PS2EXEGUI\EXE\MyExe.exe' -- 'Pas d'espace logique restant pour la création de chaînes utilisateur supplémentaires.'
      
      I investigated, and it's due to some binaries integrated in my script by converted Base64 strings (picture, pdf, ...). Whatever the Base64 string, it looks like it has some limitation. There are about ten Base64 strings in my script for binaries sized 70ko up to 2Mo. And my script is sized 6200Ko, and about 16Mo once compiled.
      
      I found more information here:
      https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/performance-considerations#strategies-for-improving-performance
      It's talking about the size limit with large and complex models. But I don't know how to do. 
      
      Thanks for your Help.
    • Hello AG_G1,
      
      you have a similiar problem that jackofalltech has (see question "Over Come 16777214" below), a string in C# is limited to a size of 16 MByte. Since PS2EXE-GUI compiles to C# and the PS1 script is held in a string variable in C#, this is a fixed limit!
      
      C# is storing ist strings UTF16 encoded, so the size of your script will be doubled. Additionally it is converted to a base64 string which leads to a another growth in size of 33 percent. This is the reason why your script raises from 6 MByte to over 16 MByte when compiled.
      
      I thought about it, but I found no way to get along with it. It is a hard limit. Please try to build smaller scripts.
      
      Greetings
      
      Markus
      
      
    • AG_G1 and Markus, 
      
      I never found a solution to the issue but i did find that if you remove some of the comments in the ps2exe script that helps, Also in the script you are converting if you use Vs Code run the convert indentations to tab this will help. its not just the size of the script but also the number of characters in the script. 
  • hang over hash table
    6 Posts | Last post March 27, 2019
    • I compiled the ps1 file which get hash table from another ps1 program.
      but, compiled program didnt work.
      
      "ERROR: cant attach Index to type System.String Object" (transfered from Japanese, so it may be some difference)
      
      How to solve this problem ?
      thank you.
      
      *test_program1.ps1
       ---------------------- 
      $HashTable = @{
          "001" = "test1"
          "002" = "test2"
      }
      ./test_program2.exe $HashTable 
      -------------------------
      
      *test_program2.exe
      -------------------------
      Param($HashTable)
      Write-Host $HashTable["test1"]
      Write-Host $HashTable["test2"]
      --------------------------
    • sorrry, there is mistake.
      
      *test_program2.exe
      -------------------------
      Param($HashTable)
      Write-Host $HashTable["001"]
      Write-Host $HashTable["002"]
      --------------------------
    • Hello papamanman,
      
      I'm sorry to say that this cannot work. PS2EXE compiles scripts to real executables, and all executables have only access to parameters of the type string! Parameters of a complex type like HashTable can only be passed to Commandlets or PowerShell functions.
      In your case your HashTable is implicitly converted to a string so the compiled script only gets the string "System.Collections.Hashtable" as parameter.
      
      There is nothing I can do about this since this is a limitation of the shell.
      
      Greetings
      
      Markus
      
    • Hello papamanman,
      
      you might work around the limitation if you store the object in a XML file:
      
      *test_program1.ps1
      ---------------------- 
      Export-Clixml Hashtable.xml
      ./test_program2.exe "Hashtable.xml" 
      
      -------------------------
      
      
      *test_program2.exe
      -------------------------
      Param($XmlFile)
      $HashTable = Import-Clixml $XmlFile
      Write-Host $HashTable["test1"]
      Write-Host $HashTable["test2"]
      
      Greetings
      
      Markus
    • Sorry, a mistake in *test_program1.ps1, correct is
      $HashTable | Export-Clixml Hashtable.xml
      
      
      
    • Hi Markus,
      
      I understood PS2EXE cant convert HashTable.
      Your alternative idea is good for my purpose.
      
      Thank you so much! 
  • Exit codes
    5 Posts | Last post March 18, 2019
    • It looks like in something has changed with exit codes,Ending a script with Exit 1 no longer fills the $LASTEXITCODE.  
    • This is only on exe files created with -NoConsole
    • Hello jackofalltech,
      
      this behavior is not PS2EXE specific, it is Windows specific for programs compiled to "WINEXE" (-NoConsole).
      
      In a cmd.exe you get the Errorlevel of those programs with the following code (for Powershell there are similiar ways):
      
      start /wait NoConsoleProg.exe
      echo %ERRORLEVEL%
      
      
      Greetings
      
      Markus
      
    • I could have swore this was working a few weeks ago 
    • Hello jackofalltech,
      
      that never worked. Just start "notepad.exe" from a command line (cmd.exe or PowerShell.exe) to see what I mean. You cannot get an exit code from a program that is independently running, you have to (manually) wait for it to exit.
      
      Greetings
      
      Markus
31 - 40 of 143 Items