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: https://github.com/MScholtes/TechNet-Gallery

PS2EXE-GUI.zip
 
 
 
 
 
4.7 Star
(38)
36,226 times
Add to favorites
5/6/2020
E-mail Twitter del.icio.us Digg Facebook
  • Powershell 7
    2 Posts | Last post March 10, 2020
    • Hello, since Powershell 7 Final is out now i would like to know if there will be a newer version soon where i can compile my PS7 script?
    • Hello Jamal1337,
      
      the issue with PS2EXE and PowerShell 6 or 7 is the underlying .Net Core. PS2EXE compiles a frame C# program containing the PowerShell script. .Net Core (and so PowerShell 7) does not deliver a compiler anymore in its base installation, one has to install the SDK to get one ("Roslyn").
      
      And once there is the compiler, the calling method has changed completely. I do not know how to implement this without weeks of work.
      
      If someone has a good idea how to make it "cheap", please tell.
      
      Greetings
      
      Markus
      
  • Odd question
    4 Posts | Last post March 06, 2020
    • Hi Markus, first off, I love the script, and I think it's great in making running powershell scripts more accessable for the regular folk out there, so I use it a lot work related..
      But here's the thing, a while ago I put together a script and used your tool to convert it into an exe, but I have not used it in quite a while since it's purpose was very specific.
      Now someone has approached me about that program/script and has made me an offer to buy it from me, whereas normally I'm all for free and open software, this case is a little bit different, also I could just sell him the ps1 but he seems to prefer the wrapped exe version, so my question is, is there anything in the PS2EXE license that would restrict or hinder me from selling the eventual exe file of my program? Or do I still keep all the same rights over the exe file as I would the original ps1 file?
      
      Also, just wondering, is it possible to disable obfuscation?
    • Hell Eanske,
      
      PS2EXE is published under the MS-LPL License that you can study above. The conditions allow to compile your script and sell the resulting executable as long as you do not remove any copyright Terms. But please see all condition terms.
      
      What do you mean with obfuscation? There is no obfuscation in PS2EXE, the original script is converted to Base64 to avoid errors with special characters. You can get the original script by calling the compiled executable with the parameter /extract.
      
      Greetings
      
      Markus
    • Oh sorry I mean base64 yes, I was under the impression that was considered obfuscating..
      The thing is the resulting exe doesn't seem have any other copyrights on them other than the one I gave it before compiling.
      I'm a sysadmin, but not much of a legal expert unfortunately, but is the compiled exe result considered part or a portion of the PS2EXE software?
      Because would that mean 3C is applied from the license?
      
      Kind regards
    • Hello Eanske,
      
      it is fine for me if you sell your compiled script. But the MS-LPL license is still binding for the part of PS2EXE in your compiled script. One could divide the base64 part and the rest of the executable and use the rest according to the MS-LPL license.
      
      If I was you, I would not care.
      
      Greetings
      
      Markus
  • Form opens just fine but button clicks are not working
    2 Posts | Last post February 27, 2020
    • I have Grid-view in my form ,3 buttons in it and 2 others buttons in form not in gridview but non of this buttons are working, when clicked  it doesnt seem like triggering the button click
      Example:
      $btnclose_Click = {
      	$MainForm.Close()
      } 
      
      $btnclose.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]420,[System.Int32]510))
      $btnclose.Name = [System.String]'btnclose'
      $btnclose.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]125,[System.Int32]27))
      $btnclose.TabIndex = [System.Int32]17
      $btnclose.Text = [System.String]'Close window'
      $btnclose.UseVisualStyleBackColor = $true
      $btnclose.add_Click($btnclose_Click)
      
      Any suggestions?
    • Hello Sathish,
      
      I do not know the reason for this behaviour but it might has to do with variable scopes that changed from Powershell V2 to V3. Please try to use $SCRIPT:MainForm instead of $MainForm in your example above.
      
      Greetings
      
      Markus
  • Start-Script is not working normally in EXE
    3 Posts | Last post February 25, 2020
    • I tested Start-Script is not working working normally after transferred from PS1 to EXE. Please take a look. Thanks!
    • Sorry for the confusion. The Cmdlet is Start-Transcript. It looks like not working fine (record information to the file)
    • Hello AW L,
      
      beginning with Powershell V3 Microsoft made a weird implementation of Start-Transscript with mixing the code into the Powershell and the underlying host. So I did not implement this commandlet and have no plans to do so.
      
      Sorry for that.
      
      Greetings
      
      Markus
  • Nach Erstellung einer *.exe mit ps2exe keine highlighted buttons
    2 Posts | Last post February 21, 2020
    • Hallo Markus,
      
      danke erstmal für dieses hilfreiche und nützliche Tool.
      
      Ich habe ein Skript mit Buttons und Progressbar. Wenn ich dieses Mittels ps2exe konvertiere, sind die Buttons nicht mehr "highlighted" und die Progressbar sieht auch anders aus, als wenn ich das Skript einfach so ausführe. Ich habe diese Frage bereits im Microsoft Technet gestellt, dort hatte man zwar Ideen, aber letztendlich hat man mich hierher verwiesen. Da ich hier keine Funktion zum Einfügen von Bildern gefunden habe, hinterlasse ich hier mal einen Link aus dem Forum, da ich dort 2 Beispiele in Bildform angehängt habe. https://social.technet.microsoft.com/Forums/de-DE/a05c6a1a-eae4-4add-a6c7-43cd43d403c9/nach-erstellung-einer-exe-mit-ps2exe-keine-highlighted-buttons?forum=powershell_de
      
      Was kann ich tun, damit die Buttons und die Progressbar so aussehen, wie sie in Bild 1, also bei Ausführung des Skriptes, aussehen?
      
      Vielen Dank.
      
      Gruß
      Christian
      
    • Hallo yelw0rc,
      
      du musst das Kommando 
      [System.Windows.Forms.Application]::EnableVisualStyles()
      in dein Skript einfügen, und zwar bevor irgendwelche graphischen Objekte erzeugt werden. Damit sollte es dann klappen.
      
      Gruß
      
      Markus
      
      
      Hello yelw0rc,
      
      you must insert the command 
      [System.Windows.Forms.Application]::EnableVisualStyles()
      into your script before any graphical objects are created. This should work then.
      
      Greetings
      
      Markus
      
      
  • Sending Parameters to exe from Commandline
    4 Posts | Last post February 20, 2020
    • Hi Markus,
      
      This is related to the $PSScriptRoot code from JacquesFS.
      When running from the Commandline the Script Root can still not be found.
      I've edited JacquesFS's Script with a little trick at the end to retrieve the Script Location from CMD.
      
      if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript"){
          $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
      } else {
          $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0])
          if (!$ScriptPath){
              $ScriptPath = Invoke-Command -ScriptBlock { cmd /c echo %CD% }
          }
      }
      
      I hope this helps someone.
      
      Nick
    • Hello Nick Zimmermann,
      
      did you check my solution for this issue I described in the Remarks section of this web page? It's shorter.
      
      Greetings
      
      Markus
    • I think you misunderstood me. JacquesFS's code would still be required. But if the same application is run from cmd then it would result in a '.' ($ScriptPath = "." }). if that segment is replaced with (shortened): $ScriptPath = icm {cmd /c echo %CD%} it will return the ScriptRoot correctly.
    • Hello Nick Zimmermann,
      
      I did not misunderstood you. The situations where JacquesFS's solution returns an empty string are when the compiled scripts are called from a command line in the directory of the script. In this situation returning a '.' is correct and working. But if you insist on having a fully qualified path, you can use your solution.
      
      (Please do not tell anybody that our solutions return the current directory, which need not be the directory of the script)
      
      Greetings
      
      Markus
  • Start-job in my script , does not work after coverting to exe
    2 Posts | Last post January 31, 2020
    • I am using start-job in my code to monitor one command.
      after compiling i realize that exe is not capable to run that start-job chunk.
      
      any idea ?
    • Hello Sushant7958,
      
      Start-Job is working fine in PS2EXE. But if the compiled script ends all still running background jobs will be forcefully closed. That's part of the design.
      
      Greetings
      
      Markus
  • TLS support
    3 Posts | Last post January 31, 2020
    • Hello Markus,
      
      Thanks again for your work. But I have an issue to download some files.
      My script is compiled with "-runtime20 -STA" arguments.
      Since the website where I download the files doesn't support TLS 1.0 and TLS 1.1 anymore, I can't download. The website supports now TLS 1.2 and TLS 1.3.
      I download correctly if I don't use the "-runtime 20" argument.
      
      Is there something you or I can do?
      This my function to download:
      
      $DLurl = 'https://...'
      $DLlocation = "D:\"
      $targetFile = "$DLlocation$DLexe"
      function downloadFile($url, $targetFile){
      $Wait4DL = New-Object system.Windows.Forms.Form
      $Label4DL = New-Object System.Windows.Forms.Label
      $Wait4DL.ControlBox = $false
      $Wait4DL.Controls.Add($Label4DL)
      $Wait4DL.StartPosition = "CenterScreen"
      $Wait4DL.TopMost = $True
      $Wait4DL.Size = New-Object System.Drawing.Size(375,50)
      $Label4DL.Text = "Downloading $DLexe ..."
      $Label4DL.Autosize = $true
      $Wait4DL.Visible = $True
      $Wait4DL.Update()
      $url = "$DLurl$DLexe"
      $uri = New-Object "System.Uri" "$url"
      $request = [System.Net.HttpWebRequest]::Create($uri)
      $request.set_Timeout(15000)
      $response = $request.GetResponse()
      $totalLength = [System.Math]::Floor($response.get_ContentLength()/1024)
      $responseStream = $response.GetResponseStream()
      $targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create
      $buffer = new-object byte[] 10KB
      $count = $responseStream.Read($buffer,0,$buffer.length)
      $downloadedBytes = $count
      Write-host "`r"
      while ($count -gt 0){
      [System.Console]::CursorLeft = 0
      [System.Console]::Write("$DLexe : {0} Ko of {1} Ko", [System.Math]::Floor($downloadedBytes/1024), $totalLength)
      $targetStream.Write($buffer, 0, $count)
      $count = $responseStream.Read($buffer,0,$buffer.length)
      $downloadedBytes = $downloadedBytes + $count}
      $targetStream.Flush()
      $Wait4DL.Close()
      $targetStream.Close()
      $targetStream.Dispose()
      $responseStream.Dispose()}
      $DLexe = "File1.exe"
      downloadFile "$DLurl$DLexe" "$DLlocation$DLexe"
    • I found the solution to support TLS 1.2 with Powershell V2.
      I add those lines in my script:
      
      $TLS12 = [Enum]::ToObject([System.Net.SecurityProtocolType], 3072)
      [System.Net.ServicePointManager]::SecurityProtocol = $TLS12
      
      I tried to replace 3072 by 12288 to support TLS 1.3, but that doesn't work. Anyway, TLS 1.2 is fine for me.
    • OK, it's fine that you found a solution (that does not really has connections to PS2EXE but to PowerShell V2).
      
      Greetings
      
      Markus
  • PSScriptRoot
    2 Posts | Last post January 31, 2020
    • I am using $PSScriptRoot in my script, it works when I manually run the script but if I use this tool to convert it to executable, it will point to C:\
      
      How do I fix this?
      
    • Hello Jari,
      
      please read the explanation on the buttom of this page in Script variables: under Remarks.
      
      Greetings
      
      Markus
  • Running EXE as another user
    2 Posts | Last post January 27, 2020
    • Hello,
      
      This little program is great for handing completed PS scripts to helpdesk folks without having to explain how to launch PS and run the script.  I have noticed though that if I run the EXE using shift+right click > run as different user, when the PS script has completed, the process is not exiting.  It stays in task manager until I kill it.  Does not seem to happen if I just double click the file.
      
      Any way to fix this so the process closes as expected when done?
    • Hello nickp85,
      
      this sounds a bit complicated. I think there is an issue with using PoshRSJob in PS2EXE. PoshRSJob starts a powershell runspace pool without closing it. Powershell.exe forcefully closes all runspaces on exit, but PS2EXE is running in a runspace by itself. So it waits for the runspaces to close what never happens, this leads to an infinite wait.
      
      I found no easy way to tell PoshRSJob to close its runspaces, so I see two workarounds:
      
      1. Change the runspaces of PoshRSJob to use its own threads
      
      Search for the file Start-RSJob.ps1 in the module directory of PoshRSJob, if installed for the AllUsers context the path is "C:\Program Files\WindowsPowerShell\Modules\poshrsjob\1.7.4.4\Public\Start-RSJob.ps1".
      
      Edit the file and insert the line
        $RunspacePool.ThreadOptions = "UseNewThread"
      in the line before
        $RunspacePool.Open()
      (line 524 as of version 1.7.4.4)
      
      Since PoshRSJob runspaces use their own threads now they can be distinguished from PS2EXE's runspace and get closed on exit.
      
      If you want the runspaces to close faster at the end replace 
        $RunspacePool.CleanupInterval = [timespan]::FromMinutes(2)
      with something like
        $RunspacePool.CleanupInterval = [timespan]::FromSeconds(10)
      two lines before the expression mentioned above.
      
      
      2. Close the runspaces manually on exit of your script
      
      Put the following line on all places of your script where an exit can occur:
      
      Get-Runspace | ?{ $_.Id -ne [System.Management.Automation.Runspaces.Runspace]::DefaultRunspace } | ?{ $_.RunspaceAvailability -lt 3 } | %{ $_.Dispose() }
      
      This line closes all runspaces that are not "Busy" and obviously not the default runspace (you would crash the script engine then). I would not recommend to do this in regular scripts.
      
      Hope this helps.
      
      Greetings
      
      Markus
1 - 10 of 184 Items