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.
4.7 Star
33,475 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Disabling popup dialog window
    2 Posts | Last post June 08, 2018
    • Hi Marcus,
      Thank you for your great tool.
      I have a question about how to disabling popup dialog window when executing the exe file after converting.
      I found your following comment in a previous similar question.
      >You have to change it to
      Is it ps2exe.ps1 to be modified? 
      I could not find the similar description "$Window.Showdialog()" in the file.
      The version I installed is PS2EXE-GUI v0.5.0.10.
      Could you designate the place where I should change in the file?
      Best regards,
    • Hello ManabuJP,
      it is a bit more complicated. You have to identify each command in your script that generates Output you don't want. You have to insert [VOID] in front of each of those lines or better pipe the output to out-null to suppress the output.
      get-item c:\ | out-null
  • Output.exe -extract:C:\Output.ps1 - protection again this
    3 Posts | Last post April 30, 2018
    • Hi Markus,
      Is it possible to protect my script from "Output.exe -extract:C:\Output.ps1" to avoid code theft? 
    • I think I found the solution, that is to remove the -extract. But still would like to know from the expert. 
    • Hello AnkitChauhan,
      removing the "-extract" option will hide the source code from curious eyes.
      But an experienced cracker will have two choices left to get the source code:
      1. Search for the base64-encoded string in the executable that represents the script
      2. Start the program and read the process memory with a debugger.
  • Topmost=true gets lost
    2 Posts | Last post April 21, 2018
    • Hi Markus,
      in my script I set $form.Topmost = $true for my Input form. However when I compile the exe, app always starts in the Background. Is there a way to set an Option when compiling?
    • Hello Chris,
      with PS2EXE you create a new application. When you start your compiled script there are two applications running: 
      - the powershell where you started the compiled script
      - the compiled script
      The $form.Topmost attribute only sets the window order of windows inside one application, not between applications (powershell and compiled script), so the behavior is different when compiled. You have to bring the application to the front, not the form window.
  • Using $Host.UI.PromptForCredential
    3 Posts | Last post April 17, 2018
    • Hi! And thanks again!
      When I’m using $Host.UI.PromptForCredential via PowerShell ISE and press cancel then result is blank/empty, as probably should be to indicate no user info entered/accepted. When I exe it (script) then … still is values in fields (user name and password, if any) passed and … can’t check when cancel is pressed.
      Any ideas?
      More thanks, Alar.
    • Using check afterwards "$Credentials.Password.Length -eq 0" seems to "save the day". Probably this is ok.
      Btw. Noticed that when in ISE clear user name field OK-button greyed out, no such behavior in exe and when clicked OK justified error appear.
    • Sure, Try & Catch wrap helps with this empty user name option.
  • Using Get-Credentials
    5 Posts | Last post April 17, 2018
    • Hi and thank You for work!
      I’m using in script Get-Credentials and those creds later in conjunction with New-SFTPSession cmdlet (from Posh-SSH module). In plain script FTP-connection using entered creds is made ok, but … after compiling … not. When I check creds user name it’s preceded with “\” e.g. “\Alar” instead of “Alar” shown in Get-Credentials, not sure this is the reason for error, though.
      Probably I’m doing something wrong. Any ideas?
      More thanks, Alar.
    • Yes, definitely this “\”. I replaced it in UserName and … everything goes well also in exe. Don’t know (at this moment) where it comes from.
    • Hello Alar,
      I can replicate the issue. The code is requesting a domain logon which is in the form domain\user. Since the domain Name is missing the result is "\user".
      I have to investigate further, since I don't request this in the code of PS2EXE.
    • Hello Alar,
      released a new version of PS2EXE today. Get-Credential is assuming a generic credentail object now so no leading backslash occurs on non domain credentials anymore.
    • Hi and thank You!
  • Two output of verbose in console
    2 Posts | Last post April 07, 2018
    • This is not the question but answer to one of the recent post i made in forum. Two verbose output was coming in console after conversion to EXE. However this seems to resolve with version I downloaded from here ( Thanks in Advance. 
    • Hello Pradeep-Papnai,
      since Ingo Karstein obviously does not work on PS2EXE anymore, I overworked his script so many errors are fixed. Among those errors were the "doubled" VERBOSE and WARNING handlers you suffered of.
  • How to suppress all of the GUI boxes that pop up after enabling noconsole?
    3 Posts | Last post April 02, 2018
    • I add the -noconsole switch to ps2exe but because my script has 15 actions it is performing, it displays that dialog box 15 times which is not what the users would want to see or keep clicking. Is there anyway I can disable that GUI output too while hiding the console? Thanks. 
    • Hello Raviolikant,
      I'm sorry there seems to be kind of misunderstanding. -noConsole meens no console output but it does not mean no output at all.
      You have two choices to work around:
      1. Capture each output in your script:
      You can does this in different ways, maybe by piping to Out-Null
      (Senseless) Example:
      Get-ChildItem | Out-Null
      2. Compile without the parameter -noConsole and hide the console window in your script:
      Include the following lines at the start of your script
      Add-Type -Name WinAPI -Namespace Native -MemberDefinition '
      public static extern IntPtr GetConsoleWindow();
      public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
      function Show-Console
      	$ConsoleHandle = [Native.WinAPI]::GetConsoleWindow()
      	[Native.WinAPI]::ShowWindow($ConsoleHandle, 5) | Out-Null
      function Hide-Console
      	$ConsoleHandle = [Native.WinAPI]::GetConsoleWindow()
      	[Native.WinAPI]::ShowWindow($ConsoleHandle, 0) | Out-Null
      After that you can call
      to hide your console window and
      to show the console again
    • Thank you very much, Markus! That helps me a lot. Thank you, I appreciate it!
  • .net error
    5 Posts | Last post March 30, 2018
    • Hello Markus,
      I used your script many times (thanks for it), but I can't use it for my last script and I can't find my problem, I hope you will be able to help me.
      So it's simple script to manage group membership of AD users. I'm using Windows form,  and this script is 90% similar to all my others scripts.
      I think there is only one difference, one of my function export list in txt file on my C: and in other function i use "Get-Content" command to read this file and display it in ListBox.
      So if i execute my script from ISE, it works but if convert it in EXE file with PS2EXE, when I start EXE file I have .NET error :
      ************** Exception Text **************
      System.InvalidCastException: Specified cast is not valid.
         at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
         at System.Windows.Forms.StringSource..ctor(String[] strings)
         at System.Windows.Forms.TextBox.SetAutoComplete(Boolean reset)
         at System.Windows.Forms.TextBox.OnHandleCreated(EventArgs e)
         at System.Windows.Forms.Control.WmCreate(Message& m)
         at System.Windows.Forms.Control.WndProc(Message& m)
         at System.Windows.Forms.TextBox.WndProc(Message& m)
         at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      Thanks for your help.
    • Hello Florian,
      it is really hard to tell what is going wrong with your script. Maybe you have to compile it with the -STA parameter?
      If this does not help, I Need more information. What OS and Powershell version you are using (while compiling the script and while using the compiled binary). When does the error occur? What is your script doing?
    • So, with "-STA" it's working :)))))))
      What is this option for ?
    • Hello Florian,
      fine it's working now.
      STA stands for Single Thread Apartment as opposed to MTA (Multi Thread Apartment). 
      When compiling with -STA the whole process works in one thread. 
      The problems you were facing have nothing to do with PS2EXE, Powershell or .Net, it is a COM issue. When calling some Windows file dialog controls in the background COM calls are made which only work in STA mode.
      STA mode is default for Powershell V3 or above, Powershell V2 is using MTA as default. So I guess you are using Powershell V2.
    • Hello Markus,
      OK thank you for these explications !!
      It's PS V4 that's running on my server, but it works with -STA, so I will not try to find why it's not STA mode by default on my server ... !
  • Error Message False on close
    2 Posts | Last post March 07, 2018
    • At First thx for this great Tool!
      i converted my PS1 with XAML WPF GUI and almost everything works, only on close of the Application i get an Error Message "False" with an "OK" Button. 
      How can i disable this message?
      thx for any help.
    • Hello benzu,
      when you compile a script with the option "-noConsole", every output is displayed in a messagebox.
      I have a guess what the reason for this is in your script:
      You start the WPF window somewhere in your script with a command similiar to this (the name of the variable $Window may vary):
      You have to change it to
      as the command returns the text "false" which is then displayed in a message box. [VOID] "eats" everything returned, so "false" is not displayed anymore.
  • 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.
81 - 90 of 143 Items