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


  • Error after conversion
    3 Posts | Last post May 02, 2017
    • Hello Markus,
      
      i converted a script to exe but after conversion i get an error that its unable to find type [System.Windows.Messagebox]. When i run the script in Powershell ISE it runs without problems.
      a piece of the code is:
      Function Resetpassword {
      
          IF ($objPasswordBox.text -eq $objPassword2Box.Text) {
          Set-ADAccountPassword -Identity "$User" -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$Password1" -Force)
          IF ($objCheckChangePasswordAtLogon.Checked -eq $true) {
          Set-ADUser -Identity "$User" -ChangePasswordAtLogon $True
          }
          [System.Windows.MessageBox]::Show('Het wachtwoord is aangepast.')
          }
          IF ($objPasswordBox.text -ne $objPassword2Box.Text) {
          [System.Windows.MessageBox]::Show('De wachtwoorden komen niet overeen')
          }
          $objPasswordBox.clear()
          $objPassword2Box.clear()
      }
      
      I'm totally new to this and have no idea how fix this. I googled and found to add [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") or Add-Type –AssemblyName System.Windows.Forms to the script, but both didn't work. 
      
      Do you have any idea?
      Thanks
      Paul
    • Hello Paul,
      
      please try [System.Windows.Forms.MessageBox]::Show('...') instead of [System.Windows.MessageBox]::Show('...'). You have to insert the command LoadWithPartialName("System.Windows.Forms") or Add-Type –AssemblyName System.Windows.Forms at the beginning of the script too.
      
      Greetings
      
      Markus
    • Hello Markus,
      
      That worked, Thanks.
      
      Greetings
      Paul
  • Is need for executionpolicy eliminated with converting to EXE?
    2 Posts | Last post April 13, 2017
    • Does using this tool to convert to an .exe preclude the need to use the -executionPolicy parameter when running a .ps1 script?  If we still need to include an executionPolicy somehow, how do we accomplish that in conjunction with converting to the .exe using this tool?
      
      Thank you!
    • Hello clh54,
      
      PS2EXE compiled scripts ignore execution policies.
      
      Greetings
      
      Markus
  • Require Admin permissions
    2 Posts | Last post April 13, 2017
    • Would it be possible to add a command line parameter to make the .exe file require admin rights, triggering the UAC prompt?
      
      I looked at the resulting .exe file contents using a text editor and I see the manifest info at the end of the .exe contents where it shows requestedExecutionLevel level="asInvoker".  I need that to be RequireAdministrator (I think that's the value.)
      
      Thank you!
    • Hello clh54,
      
      I'm sorry but I do actually not plan to make this available as an option, maybe in some future version.
      
      You can use the fork of Stuart Dootson which has an option for it: https://gallery.technet.microsoft.com/PS2EXE-GUI-Convert-9b4b0493
      
      Or you can use "mt.exe" from Microsoft which comes with the Windows SDK (or Visual Studio). I use this tool to set the requireAdministrator for my programs.
      Example call:
      mt -manifest "requireAdministrator.manifest" -outputresource:"UACTest.exe";1
      
      Greetings
      
      Markus
      
      
  • -mta vs -sta FolderBrowserDialog
    2 Posts | Last post April 10, 2017
    • -mta option does not work for below
      
              $Folder = New-Object System.Windows.Forms.FolderBrowserDialog
              $Folder.Description = "Please select a directory"
              $Folder.ShowNewFolderButton = $True
              [void]$Folder.ShowDialog()
      
      However it works with -sta
    • Hello Hans,
      
      this is a restriction of the COM object model. Some COM objects only work in Single Thread Apartment mode (=STA). There is nothing we can do about it.
      
      Greetings
      
      Markus
  • Error in System.Xml object
    3 Posts | Last post April 10, 2017
    • Hi,
      
      Below function works well in ISE however after the conversion with your tool I am getting error. This is only the piece which have an error all informs are working just fine.
      
      function ShowHTML ([string]$html,[int]$Height,[int]$Width){
          [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
          [xml]$XAML = @'
          <Window
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              Title="" WindowStartupLocation="CenterScreen">
                  <WebBrowser Name="WebBrowser"></WebBrowser>
          </Window>
      '@
          $reader=(New-Object System.Xml.XmlNodeReader $xaml) 
          $Form=[Windows.Markup.XamlReader]::Load( $reader )
          $Form.Width = $Width
          $Form.Height = $Height
          $WebBrowser = $Form.FindName("WebBrowser")
          $WebBrowser.NavigateToString($html)
          [void]$Form.ShowDialog()
      }
    • Hello HansCheska,
      
      I can reproduce an error with the original ps2exe script, but when I compile and run your script with my version of ps2exe, I get no error and the HTML document is displayed in a WPF window.
      
      Can please verify you are really using my version of the script?
      If the error persists, what error appears?
      
      Greetings
      
      Markus
    • It works. Thanks
  • this application stopped working
    2 Posts | Last post March 21, 2017
    • Hi,
      
      I have tried your new and improved version V0.5.0.3 to resolve the error "this application stopped working" when exiting my script converted with original PS2EXE V0.5.0.0 and using -noconsole parameter. It's the only bug I had. You talked about a problem with "the call of console methods" for a similar bug in the original version forum.
      
      The problem is now resolved with your version but there is so many differences between your version and the original, my very long script is not working the same way as before after the conversion.
      
      Please, do you know if it would be possible or too much complex to modify the original PS2EXE V0.5.0.0 with this unique modification?
      
      Thank you for your support,
      
      Daniel
    • Hello Daniel,
      
      there are many calls to the Console class in the original PS2EXE even when the switch -noConsole is provided, so it's very hard to say which call leads to the error.
      
      I would first try to remove the Console.CancelKeyPress handler:
      remove lines 1193 to 1206 in PS2EXE.ps1
      
      This has the side effect, that you might cannot stop your compiled script with Ctrl-C anymore (when no -noConsole is provided).
      
      I may can help you further when you tell me what the difference is when you compile your script with my version of PS2EXE compared to the original version. Are there unwanted messageboxes appearing? Or an unexpected inputbox?
      
      Greetings
      
      Markus
      
      
      
  • Simple script just failing
    5 Posts | Last post March 10, 2017
    • I compile the following code with your tool:
      [string]$scriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent 
      
      "P@ssword1" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "$scriptDirectory\Password.txt"
      $User = "MyUserName"
      $File = "$scriptDirectory\Password.txt"
      $MyCredential=New-Object -TypeName System.Management.Automation.PSCredential `
       -ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)
      
      And it end up failing saying it was filter with -include or -exclude. But it is working directly from PowerShell on Windows 10.
      
      I used the build examples and just change the path. 
      
    • Hello FRacine,
      
      the reason for the error is that $MyInvocation does not work in the compiled script, some of the autogenerated variables are not filled.
      Maybe this is working for you:
      
        [string]$scriptDirectory = $pwd
      
      Greetings Markus
      
    • I've done some further Analysis on this topic.
      
      The reason why $PSScriptRoot and $MyInvocation.MyCommand.Definition are empty is that a script is no script anymore when compiled with PS2EXE. There is nothing I can do about it.
      
      Greetings Markus
    • Hi,
      
      Instead of "Split-Path -Path $MyInvocation.MyCommand.Definition -Parent 
      " use "Split-Path -parent ([Environment]::GetCommandLineArgs()[0])"
      
      That gets your execution location.
      eg if your .exe is located at C:\it\test.exe it would return C:\it as the scriptdir.
    • Hello JacquesFS,
      
      this is really a great hint.
      
      Thank you
      
      Markus
  • Progress
    5 Posts | Last post March 06, 2017
    • Hi. In my script, I install Framework by "Add-WindowsFeature as-net-framework" or use Start-BitsTransfer to download files.
      What should I change in your script to show progression in the console?
      Thanks.
    • Hello AG_G1,
      
      the provision of Write-Progress in the console is very complex. For this reason I will probably not program this and Write-Progress will be further ignored.
      
      In the next week I will release a new version of PS2EXE that is able to show progress when the script is compiled to a GUI executable (via -noConsole). Maybe this will help you.
      
      Greetings
      
      Markus
      
    • OK, I understand. I'll try your new version.
      
      Thanks for your support.
    • I tried the noConsole parameter with the actual version, but I've a kind of issue.
      It shows up one by one every object that i get with the Get-ChildItem cmdlet.
      I tried with "out-null" or ">null" but it's worse it gets nothing.
    • Hello AG_G1,
      
      as stated in the Remarks section the output of commandlets is formatted line per line (as an array of strings). So in GUI mode one messagebox appears for every line of output. You have to convert the output to a string array with the commandlet Out-String, e.g.
      
      Get-ChildItem | Out-String
      
      Then there is only only messagebox with the Output.
      
      Greetings
      
      Markus
  • Runtime20 error
    5 Posts | Last post March 05, 2017
    • Hi! Thanks for your work, but I have an issue with the Runtime20 parameter.
      
      I have a script to make scheduled tasks, and in its firsts steps I check if Framework 3.5, 4 and WMF 3.0 are setup if I'm on Windows Server 2008/R2. If not, it call a form to download and setup missing products.
      It works fine for the Frameworks, but not for WMF 3.0. I mean it works, but it ask each time I launch the .exe if I want to setup WMF3.0, even if it's already setup and server rebooted.
      If I don't use the Runtime20 parameter, it works fine but I loose the interest as the Framework has to be already setup to make it work.
      
      Here is the part mentioned:
      
      if (('True' -eq ([Environment]::OSVersion.Version -ge (new-object 'Version' "6.0"))) -and ('True' -eq ([Environment]::OSVersion.Version -lt (new-object 'Version' "6.1"))) -and ('True' -eq ($PSVersionTable.PSVersion -lt '3.0'))) {
      	if([System.IntPtr]::Size -eq 4){
      	$DL = "Windows6.0-KB2506146-x86.msu"
      	GenerateFormWMF
      	}else{
      	$DL = "Windows6.0-KB2506146-x64.msu"
      	GenerateFormWMF
      	}
      }elseif (('True' -eq ([Environment]::OSVersion.Version -ge (new-object 'Version' "6.1"))) -and ('True' -eq ([Environment]::OSVersion.Version -lt (new-object 'Version' "6.2"))) -and ('True' -eq ($PSVersionTable.PSVersion -lt '3.0'))) {
      	if([System.IntPtr]::Size -eq 4){
      	$DL = "Windows6.1-KB2506143-x86.msu"
      	GenerateFormWMF
      	}else{
      	$DL = "Windows6.1-KB2506143-x64.msu"
      	GenerateFormWMF
      	}
      }elseif (('True' -eq ([Environment]::OSVersion.Version -ge (new-object 'Version' "6.2"))) -OR ('True' -eq ($PSVersionTable.PSVersion -ge '3.0'))) {
      }else{
      Write-Host "Not compatible"
      Read-Host -prompt "Press Enter to quit..."
      Exit
      }
      
      If you could help me please ;-)
    • I guess I found out. My solution solution would be to use Runtime20 and Runtime40.
      But when I use both parameters, it's like it doesn't consider the Runtime40 parameter.
    • Hello AG_G1,
      
      you're having intersting scripts! There are two things that come to my mind:
      
      - when you use the parameter "-runtime20" of PS2EXE, the $PSVersion variable always returns version 2 regardless of the installed powershell Version. You have to find another way to get the installed WMF version.
      - there is obviously a bug in PS2EXE you already found out. When you use the parameters -runtime20 and -runtime40 together, only -runtime20 is used (there should occurr an error message).
      
      Greetings
      
      Markus
    • I found out about the $PSVersion variable. I replaced ('True' -eq ($PSVersionTable.PSVersion -ge '3.0')) by (!(test-path "HKLM:\SOFTWARE\Microsoft\PowerShell\3")).
      But I'm still blocked by the bug you described.
    • Hello AG_G1,
      
      I will release a new version of PS2EXE in the next week. This version will stop with an error message when you supply the parameters -runtime20 and -runtime40 together.
      
      Hope that is what you need (remember: you cannot have two runtimes at one time).
      
      Greetings
      
      Markus
      
  • A couple of updates...
    4 Posts | Last post December 15, 2016
    • I've made a couple of changes to PS2EXE to fix a couple of issues (which I've documented below) I had with it. Is there some repo I can add a pull request or something, if you're interested in incorporating the changes...
      
      1. I've been having trouble with the icon file parameter, possibly because my script file's path contains spaces. In order to fix this, I changed ps2exe.ps1 to a) expect the icon file parameter to be a fully specified path (the same as $inputFile), and b) to place quotes round the '/win32icon' compiler option.
      
      2. I wanted to compile a script to run elevated. To do this, I added a command line switch named 'elevated' and when that was set $TRUE, added a compiler option to embed a manifest in the .EXE to specify that it be run as administrator.
    • Hello Stuart,
      
      I made a fork of Ingo Karstein's great script just to remove some errors and to make some basic improvements, since Ingo seems to have stopped working on it. I am not able to forward his script. I would advice you to make your own fork with your improvements.
      
      Especially the compiler option to specify a script to run as an administrator sounds very interesting, so it could be worth it.
      
      Greetings 
      
      Markus
    • Done - you can find it <a href="https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-9b4b0493">here</a>
    • Hello Stuart,
      
      cool work. You implemented some great improvements.
      
      Markus
131 - 140 of 143 Items