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,469 times
Add to favorites
7/1/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 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?
      
      Grettings
      
      Markus
    • Hi Markus!
      
      Thanks for the reply.
      
      I just enable the style right before showing the form:
      
      [System.Windows.Forms.Application]::EnableVisualStyles()
      [void]$Form.ShowDialog()
      
      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.
      
      Video: https://www.youtube.com/watch?v=nRWczDrKmNg
      
    • 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?
      
      Greetings
      
      Markus
    • 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
      $Form.Controls.Add($ProgressBar)
      
      - When I need to remove it
      $ProgressBar.size = new-object System.Drawing.Size(0,10)
      $Form.Controls.Remove($Form.Controls["ProgressBar"])
      
      - When I need to reset it
      $ProgressBar.Value = 0
      
      - To increment it 
      $ProgressBar.Value += 1
      
      Thanks
    • 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.
      
      Greetings
      
      Markus
    • 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.
      
      Thanks,
      Dark
    • 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.
      
      Greetings
      
      Markus
  • 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.
      
      Greetings
      
      Markus
  • 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.
      
      Greetings
      
      Markus
  • 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
      
      
      Why?, 
    • 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.
      
      Greetings
      
      Markus
    • 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:
      -----------
      Param(
      [string]$STLFile=""
      )
      #https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5
      
      $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)
      
      ------
      Param(
      [string]$STLFile=""
      )
      #https:\\gallery.technet.microsoft.com\scriptcenter\PS2EXE-GUI-Convert-e7cb69d5
      
      $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?
      
      
      Thanks
      /Stig
    • 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 }
       else
       { $scriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) }
      
      
      Greetings
      
      Markus
      
  • 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.
      
      Example:
      $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.
      
      Greetings
      
      Markus
      
      
    • Hello Florian,
      
      I fixed this issue with the new version 0.5.0.9 today.
      
      Greetings
      
      Markus
  • 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.
      
      Greetings
      
      Markus
    • Well, that was nice and easy!
      
      Thanks for your help.
  • Can an option be added to support Mixed Mode?
    2 Posts | Last post December 23, 2017
    • I was compiling a PS script that used Exchange Management and was getting an error like below when executing the EX commands:
      
      mixed mode assembly is built against version 'v2.0.50727'
      
      I resolved it by editing the .config file to this:
      <startup useLegacyV2RuntimeActivationPolicy="true">
      
      If there isn't an option already that I'm overlooking, can there be a switch that automagically adds that to the config file?
      
      REF: https://support.microsoft.com/en-us/help/2572158/sgen-mixed-mode-assembly-is-built-against-version-v2-0-50727-of-the-ru
      
      Great job overall, this project really saved my project many thanks to Markus and Ingo
    • Hello Joshuar75,
      
      it seems you're running the compiled script in a .Net V4 environment but referencing a .Net V2/V3.5 assembly.
      
      Since this situation is very special there is no switch to PS2EXE to make the necessary entry in the config file for the resulting binary. I hope that is okay for you.
      
      Greetings
      
      Markus
      
91 - 100 of 143 Items