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. Now here:
4.7 Star
37,897 times
Add to favorites
E-mail Twitter Digg Facebook
  • Black box flashes when runnning .exe
    4 Posts | Last post March 07, 2018
    • Simple script I want to convert:
      [Windows.Forms.MessageBox]::Show(“Test message from!. Subscribe to news letters, RSS feeds at to stay tuned”, “”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
      Conversion works fine I get the .exe.  But when launching it just a black box flashes and disappears.  I can run the script fine in powershell.
      Tried all the different switches nothing helped.
    • Hello BFrisan,
      I copied your code example, compiled it and got errors too. There are two things you may have to do to get the code working with PS2EXE:
      - When you're compiling without the PS2EXE Parameter "-noConsole" you have to add the following line before calling MessageBox:
      Add-Type -AssemblyName System.Windows.Forms
      - Your quotation marks are UNICODE characters (“ and ”) and not ASCII characters ("). Since PS2EXE expects UTF8 encoded source files you have 2 choices:
      1. Convert your source file to UTF8 encoding
      2. Replace all the quotation marks with the ASCII quotation mark
      Making those changes everything worked fine for me.
    • Thanks for that.  Working little better now.
      The last thing that is happening now is that there is an extra box that pops with OK on it.  There should only be 1 box that pops up with the message.
    • Hello BFrisan,
      the command [Windows.Forms.MessageBox]::Show(...) returns the value of the button you clicked ("OK"), so this value is displayed.
      Change the command to 
      [VOID] "eats" everything returned, so "OK" will not be displayed anymore.
  • EnableVisualStyles not working anymore with Forms
    8 Posts | Last post February 20, 2018
    • Been a While that I dont get a new version of ps2exe. I use version 5.0.0 on a Windows 7 and my script with forms can use the "[System.Windows.Forms.Application]::EnableVisualStyles()" expression and get the right style after getting the EXE version.
      But I tried with the latest version (1/4/2018) and its just broken, the style just dont work anymore. Tried the ps2exe at the same Windows 7 and on a Windows 10.
      Think this will get fixed? Thanks.
    • Hello Lemys,
      I created a small WinForms program with a style and compiled it with PS2EXE. It works just fine with Windows 7 and with Windows 10, the style is shown when run as script and is shown when compiled with PS2EXE.
      Are you sure styles are activated in your OS. Maybe your selected style is not available? Is there an error message or other strange behaviour?
    • Hi Markus!
      Thanks for the reply.
      I just enable the style right before showing the form:
      There are no errors apearing.
      I noticed that also a "progress" screen keeps poping up as well when I run a job or import a module. Dunno if thats just something I can disable.
      Posted a video to show what happens.
      First was made with version 5.0.0 second one with 5.0.9 same script no changes.
    • Hello Lemys,
      the easy answer first. PS2EXE now shows a progress bar in situations a script would do that when compiled with "-noConsole", the progress bar is displayed in a GUI window. You disable this (default) behaviour with the following line (also in "normal" powershell scripts):
      $ProgressPreference = "SilentlyContinue"
      Now to your main question. According to your video I guess you have troubles with the style of the progress bar. The rest of the form seems okay to me. Can you post the code that creates the progress bar object and sample code that displays the bar so I can check this?
    • Thanks for the "$ProgressPreference" explanation, had no idea. To remove all those little progress bar windows I had to put it in 4 diferent places in my script. Damn M$.
      About the progressbar:
      - Adds the bar:
      $ProgressBar = New-Object System.Windows.Forms.ProgressBar
      $ProgressBar.Location = new-object System.Drawing.point(15,55)
      $ProgressBar.size = new-object System.Drawing.Size(0,10)
      $ProgressBar.Minimum = $ProgressBar.Maximum = $ProgressBar.Value = 0
      - When I need to remove it
      $ProgressBar.size = new-object System.Drawing.Size(0,10)
      - When I need to reset it
      $ProgressBar.Value = 0
      - To increment it 
      $ProgressBar.Value += 1
    • o.O
      Strangely, after I set the "$ProgressPreference = "SilentlyContinue" before all the commands that made the "progress window" apear, the Style of the window started to work.
      The Progress Bar also got the right style.
      Se everything is working as expected now. Thanks e lot!
    • Hello Lemys,
      now I have an idea what was going wrong in your script. According to Microsoft: "To have an effect, System.Windows.Forms.Application.EnableVisualStyles must be called before creating any controls in the application".
      When loading any modules in PS2EXE, progress controls are generated and the calling of EnableVisualStyles() will have no effect afterwards.
      I will check if I can call EnableVisualStyles() in PS2EXE before executing the script when compiled with -noConsole.
    • Thanks again for the reply, and the research you did to find what may be the problem.
  • Packing other modules into it
    2 Posts | Last post January 30, 2018
    • Am I able to pack a module into it somehow? Say I want to send the exe to someone who doesn't have a certain Powershell module installed that my script uses. 
      I assume I could zip it along with it and have it call it locally, just wondering if there is a way to include it in the exe.
    • Hello grimdark,
      I'm sorry there is no way to pack accompanying files to an executable wirh PS2EXE. You have to use a zip file, a setup packer or send more than one file.
  • Powershell 5 support?
    2 Posts | Last post January 30, 2018
    • Does it possible that your Script add support for Powershell 5?
      Great job, thanks!
    • Hi,
      I already seen that it works with Pshell 5, I did a miss with the previous ps2exe.ps1 version..
  • Antivirus
    2 Posts | Last post January 25, 2018
    • Hello,
      Some scripts I converted into .exe are blocked by antivirus, probably because a part is working into the registry.
      Is there a way to certify or make it proper?
    • Hello AG_G1,
      I don't know if we can do anything about that. 
      Which virus scanner you are using? What is the detected virus/malware name?
      Does the Problem appear only with some scripts or all? What kind of scripts are blocked by antivirus.
  • Certificate
    2 Posts | Last post January 19, 2018
    • Hello,
      I set the executionpolicy to allsigned and got a working way to sign my scripts.
      But it got my attention that when I take a unsigned script and convert it to a .exe it doens't need to be signed and can be run from powershell.
      Is it possible that I can do something to let it check for a signature/certificate again.
      thanks for the help  
    • Hello Jeffrey,
      I'm sorry but I see no way to get PS2EXE to acknowledge the powershell execution policies. Execution policies are intended to control the use of scripts. When you compile a script to an executable it is not a script anymore. You have to use the control mechanisms intended for executables now: AppLocker or SRP (Software Restriction Policies).
      By the way, when you load a script inside a PS2EXE executable, the execution policy is honored.
  • Hello :) Why the parameter -IncludeUserName cannot be found?
    3 Posts | Last post January 15, 2018
    • I have script:
      $yum = Get-Process Notepad -IncludeUserName  
      Write-Host $yum
      echo $yum 
      after build and run, script return only:
      Get-Process : A positional parameter cannot be found that accepts argument '-IncludeUserName'.
      At line:1 char:1
      + Get-Process -Name Impuls,Hermes,LQS,PPM $yum
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidArgument: (:) [Get-Process], ParameterBindingException
          + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand
    • Hello ePawel,
      I cannot reconstruct your error. Is it possible, you're trying to run it with Powershell V2.0? The parameter -IncludeUserName does not exist with this powershell version.
    • You have got awesome idea. I built script under powershell 2.0 and run under powershell 4.0, this is my mistake, after upgrade powershell to 4.0 the error has disappeared. thanks a lot!  
  • General issue
    2 Posts | Last post January 08, 2018
    • Hi Markus - i cant get this work for some reasons.
      The script is:
      $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
      Write-Host $scriptPath
      $File = Get-Content "$ScriptPath\StartProgram.json" -Raw 
      $Config = $File.Replace("\","\\") | ConvertFrom-Json
      Write-Host $Config.Config.ProgramToStart
      Start-Process -FilePath $Config.Config.ProgramToStart -ArgumentList @($Config.Config.Arguments, $args[0]) -WorkingDirectory $Config.Config.WorkingDirectory
      made to exe with
      .\ps2exe.ps1 c:\temp\posh\StartProgram.ps1 c:\temp\posh\StartProgram.exe
      nothing really special about that
      but executing the exe gives two errors (i suspect error 2 is a problem that comes from error 1)
      $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
      Write-Host $scriptPath
      $File = Get-Content "$ScriptPath\StartProgram.json" -Raw
      $Config = $File.Replace("\","\
      ERROR: A parameter cannot be found that matches parameter name 'Raw'.
      ERROR: You cannot call a method on a null-valued expression.
      ERROR: Cannot validate argument on parameter 'FilePath'. The argument is null or empty. Provide an argument that is not
      null or empty, and then try the command again.
      Any ideas?
    • Hello Stig,
      as I stated in the "Remarks" section of the "Description" tab of this web page script related variables are not available anymore or changed, because PS2EXE compiles a script to an executable.
      In your case you have the issue, that the variable $MyInvocation is set to other values than in a script.
      You can retrieve the script/executable path independant of compiled/not compiled with the following lines:
      if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript")
       { $scriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition }
       { $scriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) }
  • Problem with Credential Provider
    3 Posts | Last post January 04, 2018
    • When I compile a script that has a credential Provider (get-credential) after being compiled, it doesn't show the Title and the text inside the Credential window.
      $objCredential = $host.ui.PromptForCredential('Access to FileServer', 'Please enter your username with domain and your password.', "domain\user", "")
      The compiled window shows "connect to" as title (instead of 'Access to FileServer') and "Connecting to" as body (instead of 'Please enter your username with domain and your password.')
      Is there a way to fix that behavior?
      Thank you and great job so far.
    • Hello Florian,
      I think I can add this request to PS2EXE. Just give me a few days time for development and test.
    • Hello Florian,
      I fixed this issue with the new version today.
  • Im unable to extract contents of EXE file
    3 Posts | Last post January 03, 2018
    • I have the following command
      PS C:\Users\User\Desktop\ps> .\ps2exe.ps1 -inputfile "C:\Test.exe" -extract:"C:\test.ps1"
      but when I run this I get 
      Input file or output file not specified!
      Any suggestions? I'm trying to decompile an exe I made with ps2exe but I'm unable to get this to work!
    • Hello Craig,
      it's much easier as you think. The extract-function is build into the executable:
      C:\Test.exe -extract:"C:\test.ps1"
      will do the work.
    • Well, that was nice and easy!
      Thanks for your help.
131 - 140 of 184 Items