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
(37)
34,258 times
Add to favorites
11/15/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 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
  • Pop Up Error Boxes
    4 Posts | Last post March 08, 2019
    • When running newly created exe, every time there is an error in the background a window pops up showing that error message.  Is there a way to turn that off?
      I have a program that checks for certain thing on a computer. But if it can't ping it all the checks it tries to perform generates these error windows which I don't need to see.
      
      I'm creating exe using 2.0.ps1\ -inputfile .\file.ps1 -outputfile .\file.exe -noconsole
    • Sorry typo above.   
      I'm creating exe using: ps2exe.ps1 -inputfile .\file.ps1 -outputfile .\file.exe -noconsole
    • That is what the -NoConsole switch will do if you want to hid the error message add -ErrorAction SilentlyContinue or | out-null to the command that is throwing the error 
    • Hello BFrisan,
      
      this behaviour is by design.
      
      You have to search for the command that generates the error and fix the error or prevent the error message by using the "-ErrorAction SilentlyContinue" option or by redirecting the error output like this (example is Get-ChildItem  for a not existing file):
      
      Get-ChildItem NotexistingFile 2> $NULL
      
      
      Greetings
      
      Markus
      
  • BrowseForFolder on top
    4 Posts | Last post March 04, 2019
    • Hello Markus,
      
      I have a form with a button to show a BrowseForFolder object.
      I wanted the BrowseForFolder object to be MostTop, so I did this:
      
          ...
          $handle = [System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle
          $object = New-Object -ComObject Shell.Application
          $folder = $object.BrowseForFolder($handle, $Message, $browseForFolderOptions, $InitialDirectory)
          ...
      
      It's working fine when I run the script, but it's freezing my form without showing the BrowseForFolder object when I run the .exe.
      Could you please tell how I can fix the $handle?
      
      Greetings 
    • This is what I use and it works for me 
      
      [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
      $SourceForm = New-Object System.Windows.Forms.FolderBrowserDialog
      $SourceForm.Rootfolder = "MyComputer"
      $SourceForm.Description = "Browse For Folder"
      [void]$SourceForm.ShowDialog()
      IF ($SourceForm.SelectedPath){$Path = $SourceForm.SelectedPath}
    • Hello AG_G1,
      
      when running your code in a compiled script, there is no window handle because you didn't created one. Please try the following code to use the parent process' window:
      ...
      $handle = [System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle
      if ($handle -eq 0) { $handle = (Get-Process -PID ((Get-WMIObject -Class Win32_Process -Filter "ProcessID=$PID").ParentProcessId)).MainWindowHandle }
      $object = New-Object -ComObject Shell.Application
      …
      
      Another problem that can occur is an issue with MTA and COM (should occur only when using PowerShell V2) that leads to freezing windows. If this is your problem try to compile your script with the additional Parameter -STA
      
      Greetings
      
      Markus
      
      
    • Thanks!
      
      I didn't change my code and add the -STA parameter, and it works fine!
      
      Thanks again.
61 - 70 of 171 Items