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,227 times
Add to favorites
E-mail Twitter Digg Facebook
  • The Handle is Invalid
    12 Posts | Last post June 11, 2018
    • I've created an EXE that runs fine interactively.  However when trying to invoke the EXE from the scheduling app VisualCron, I get the error: "The Handle is Invalid".
      Anyone have any ideas on this?
    • Hello M Woffenden,
      you don't give me enough information to find the reason for this error. I guess there is a problem with the default streams (standard input, standard output, standard error). 
      Are you trying to change the user context of the process? Do you want to elevate the process on a remote system?
    • Thanks for your reply.  You are right, there is an issue with the standard output.  In VisualCron there are two options: "store standard output" and "store standard error".  When I have either of these turned on, I get the"The Handle is Invalid" error.
      If I turn both options off, I can run the EXE version of my script.
      But I do want to store the output -- and this worked with the old version of PS2EXE.
      Any ideas on what might be happening here?  Any PS2EXE options that I should try?
    • Hello M Woffenden,
      did you compile with the Option -noConsole ? Then there is no console and of Course no console Output.
    • Compilng with -noCompile allows us to run the EXE.  But does this option prevent writing to standard output?
    • Correction: Compiling with -noConsole allows us to run the EXE.  
      But does this option prevent writing to standard output?
    • Hello M Woffenden,
      yes, when compiled with the option -noConsole you generate a "real" Windows gui program which runs without a console. But standard output, standard input and standard error are only available in a console (obviously there is no place where an output could go if no console is present).
      So you have to decide: generate an executable without console and without standard output or an executable with console and standard output.
    • Markus - becoming clearer.  
      I really do want a console app where I can write output.
      But this leads me back to my very first question.   When I create a console app and try to run it, I get the error: "The Handle is Invalid".  You said there is a problem with the default streams (standard input, standard output, standard error). 
      Any ideas on how I might debug this? 
    • Hello M Woffenden,
      now I am confused.
      When you compile without -noConsole, there should be a console and so standard output should work.
      When you compile with -noConsole, there is no console and there is no standard output so you might get the error "The handle is invalid".
      Is this your Situation?
    • Hi Markus,
      I have the same problem.
      I used the generated EXE file from ps2exe in another powershell script.
      It seems that when I activate the error output redirection, the error message "The handle is invalid" shows up.
      To reproduce the error, I just created an executable from a PS1 which prints a text and I called it in another ps1 with the following code:
      $output = &'YOURPS1EXE' 2`>`&1
      You will normally get the error message.
    • Hello M Woffenden, hello Albert Rag,
      as you found out the input stream is not working correctly under some circumstances in compiled PS2EXE scripts. I will need some time for research on this.
      What I found too (that does not produce the error): I forgot to send error output to the error stream :-) . This will be fixed in the next version of PS2EXE.
    • Hello M Woffenden, hello Albert Rag,
      the new version v0.5.0.11 released today fixes the errors with redirection
  • 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.
121 - 130 of 184 Items