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
(38)
34,565 times
Add to favorites
11/15/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Compiled with -NoConsole but there are some windows still flashing.
    5 Posts | Last post July 15, 2018
    • Hi Marcus.
      
      Right after I execute the compiled file after compiling with -NoConsole switch, I see some flashing windows and flashing icons on taskbar too.
      How to absolutely hide all windows?
      
      Greetings
      Minh Cường
    • Hello Minh Cường,
      
      I can not reproduce this behaviour. When I compile my scripts with -noConsole, there are no windows or taskbar icons appearing. Is it possible that you start something in your script needing or generating a window? Does this happen with empty scripts too?
      
      Greetings
      
      Markus
    • Hello Markus.
      
      You can test this behavior by compiling 2 examples code's line below:
      
      Example with CMDlets (compiling with -NoConsole):
      $Null = Invoke-WebRequest -uri "http://example.com/" -disableKeepAlive
      
      Example with CMD commands (compiling with -NoConsole -RequireAdmin):
      $Null = mountvol.exe x: /s
      
    • Hello Minh Cường,
      
      Invoke-WebRequest shows a progress bar, which is displayed in a new window in -noConsole mode. If you don't want this window, disable displaying of progress bars with:
      
      $ProgressPreference = 'SilentlyContinue'
      $Null = Invoke-WebRequest -uri "http://example.com/" -disableKeepAlive
      $ProgressPreference = 'Continue'
      
      mountvol.exe needs a command shell to run so it starts its own if there is no shell present. This is the window that appears for a very short time. The solution is to start mountvol.exe (and its shell) hidden:
      
      $Null = Start-Process mountvol.exe -ArgumentList 'x:','/s' -WindowStyle Hidden
      
      
      Greetings
      
      Markus
      
      
    • Thanks very much for your advice, Markus.
      
      Greetings
      
      Minh Cường
      
  • Exception Calling
    2 Posts | Last post July 12, 2018
    • When I run the exe file I get the error message ""SetBufferContents" with "2" argument(s): "Not enough storage is available to process this command"
      
      Any assistance would be greatly appreciated.
    • Hello DrHeinz,
      
      I need more information to answer to this. The function "SetBufferContents" is used for console screen manipulations, first of all for Clear-Host (or cls).
      
      Do you use Clear-Host in your script? If yes, try to comment the command out. Does the error still occur then? Do you change the size of your console in your script, or the codepage?
      
      Greetings
      
      Markus
      
  • Pop up box not showing out put
    2 Posts | Last post June 29, 2018
    • I am having some issues with longer outputs parsing Format-List | Out-String as a single line when running -NoConsole. In Powershell CanonicalName will display as a single line. With No Console, it wraps the data. 
      
      PS Command:
      Get-ADUser -Filter {samAccountName -eq $X} -properties * | select DisplayName,samAccountName,Enabled,CanonicalName | Format-List | Out-String
    • Hello jdangelo,
      
      since I use the standard WinForms output method "MessageBox.show()" to display output in -noConsole mode, there is no way to configure the formatting of the text but to insert Carriage Returns into the output text.
      
      Greetings
      
      Markus
      
  • Executing PS2EXE.ps1 inside an compiled OtherPS1.exe file problem.
    5 Posts | Last post June 24, 2018
    • Hi Markus.
      
      Example: $Args is an Array of parameters @("-noConfigfile", "-noConsole", "-requireAdmin")
      
      When I use splatting $Args, it's working only when executes Otherps1.PS1
      
      & $ps2exe $inputFile $outputFile @Args
      
      But it will fail when executes the compiled version Otherps1.EXE
      
      Output:
      ...
      You are using PowerShell 4.0 or above.
      Icon file D:\Powershell Scripts\True not found!
      
      I don't know this problem is normal when executes *.EXE file or this's a bug.
      I'm just a newbie to Powershell so if this problem is normal please excuse me :D
      
      Greetings
      MC
    • Hello Minh Cường,
      
      you cannot splat parameters to compiled scripts since they are real executables. Only commandlets can read the parameters in the collection.
      
      Greetings
      
      Markus
    • Hello Markus.
      
      In the compiled OtherPS1.exe I try:
      Write-Host $Args
      
      And the output is:
      -noConfigFile True -noConsole True -requireAdmin True
      
      Is that normal, Markus?
      
      Greetings
      
      Minh Cường
      
    • Hello Minh Cường,
      
      since there is an implicit conversion from [SWITCH] to [STRING] when splatting to an compiled script I think I cannot do anything about your error.
      
      The original PS2EXE script of Ingo Karstein did better in this situation, but had many misinterpretations of Parameters in other constellations.
      
      So I'm sorry to say that I do not guarantee proper work of splatting parameters to compiled PS2EXE scripts.
      
      Greetings
      
      Markus
    • It's not a problem, Markus :D
      
      I just want to know more about splatting parameters of your script.
      
      I will try something myself.
      
      Thanks you for your script, Markus.
      
      Greetings
      
      Minh Cường
  • Write-Progress
    2 Posts | Last post June 19, 2018
    • Any chance there will be support for Write-progress in console mode?
    • Hello TommyTrut,
      
      a proper implementation of Write-Progress in console mode would be very much work (every output would have to be hooked) for small benefit. So I do not plan to implement it.
      
      Greetings
      
      Markus
  • Script using Get-ADPrincipalGroupMembership
    8 Posts | Last post June 16, 2018
    • Hello Markus,
      I am using "Get-ADPrincipalGroupMembership" in my script. When I am running PS1 file(PowerShell script), it is giving the desired output. But, after creating exe file, the "Get-ADPrincipalGroupMembership" is not working.
      
      Please advise.
      
      Sample code:
      $s=Get-ADPrincipalGroupMembership $account_name |Select-Object -ExpandProperty saMAccountName | Where-Object {$_ -match "OOB-Management"}
      $s
    • I had the same issue.  I was able to add a line in the original script to load the module for active directory.  (Be sure to put in the actual file path not just the module name.)  After adding that line I was able to see the module actually load when the .exe is executed.
    • Hello JuanealB,
      Can you share the sample on how to add the module? Also, it will be more helpful if you provide me the actual location where I need to add the codes.
    • Hello Ashutosh Tripathi 14,
      
      as JuanealB stated right there is no autoloading of modules in compiled PS2EXE scripts.
      
      You have to load the Active Directory module manually with the command:
      Import-Module ActiveDirectory
      
      Greetings
      
      Markus 
      
    • Hello Markus,
      I am already using the "Import-Module ActiveDirectory" in my script and it is working fine when I am running the PS1 script. But, when I am generating the exe from PS1, it is not working.
      
      Thanks,
      Ashutosh
    • Hello Ashutosh Tripathi 14,
      
      your problem seems to be a bit more complicated.
      
      But to help I need to know what happens. You say "it's not working". What does this mean? Is there an error? Do you get unexpected results? Does nothing happen? Do other commandlets from the ActiveDirectory work?
      
      Greetings
      
      Markus
    • Hello Markus,
      
      Sample code:
      $sam="ashutosh.tripathi"
      $s=Get-ADPrincipalGroupMembership $sam |Select-Object -ExpandProperty saMAccountName | Where-Object {$_ -match "OOB-Management"}
      $s
      Read-Host "Please wait"
      
      When I am running this code in powershell/ps1 script I am getting correct output i.e.,"OOB-Management". But, when I am running the code after creating exe, I am not getting any output. I also tried to check with the different group names, but getting same result. 
      
      One interesting thing I found during my testing that if I replace OOB-Management with "Domain Users" group, then I am getting correct out in PS1 script as well as in exe file.
      
      Thanks,
      Ashutosh
    • Hello Ashutosh,
      
      before we dive too deep in to your script. You say it works with "Domain Users". Can this be an issue with special characters and the encoding of the source file?
      
      If special characters are used the source file has to be encoded as UTF8, 16 Bit-UNICODE works too. Encoding as ASCII or OEM can lead to side effects like those you are experiencing.
      
      Greetings
      
      Markus
  • Strange GUI
    3 Posts | Last post June 15, 2018
    • Hi Markus
      
      I have written a script that will be used on alot of servers and everytime someone logs on it should run. Now to do that I need an .exe file. When I used your script to convert my script into a .exe file, it has 7 popup windows where the first one has "0" and the second one has "1" all the way to 6. Then an error pops up saying "It is not possible, to invoke a method for an expression, which is NULL" (translated from german, might not be 1-1 but tried my best translating it).
      Now after this error my script finally pops up. But when I close it, I again get a popup window saying "Cancel" or "OK". 
      Now what might be the problem is, that I programmed my own GUI in my powershell script, but I am not the expert of what this script does.
      Is there a way to block these popup messages or another workaround? I would be thankful for your help.
      
      Thanks in advance
      Crowlex
    • "Now what might be the problem is, that I programmed my own GUI in my powershell script, but I am not the expert of what **this script** does."
      
      For clarity, I mean your script here, otherwise it would be quite confusing
    • Hello Crowlex,
      
      the PS2EXE Parameter "-noConsole" does not mean that there is no output, the output will be presented in message boxes.
      
      When you want to get rid of the Output you have to find the commands in your script (maybe in executing the script in ps1 form) that generate output and suppress it.
      
      You can do this by piping to Out-Null, e.g.
      Get-Process | Out-Null
      
      The Cancel or OK at the end of the script is the result of your GUI window. Find the expression that calls .Show() or .ShowDialog() and suppress the output with the [VOID] type, e.g.
      
      [VOID]$Form.ShowDialog()
      
      Greetings
      
      Markus
      
  • Get-Credential Stays in Console
    6 Posts | Last post June 14, 2018
    • Markus,
      
      Great work and thank you so much for creating this! I have an issue where Get-Credential only shows up in the console window after being converted. VB popups still work, but I cannot seem to get the proper credential window to appear.
      
      Please advise.
      
      Charlize
    • Hello Charlize V,
      
      do I understand your question right: you are compiling a script without using the Parameter -noconsole and wonder why there is no graphical dialog when calling Get-Credential?
      
      This was a decision Ingo Karstein made when initially creating the script. I think it was a good decision but I will check how to change this behaviour. This might take some time, hope that's okay for you.
      
      Greetings
      
      Markus
    • Hello Charlize V,
      
      the new version v0.5.0.11 of PS2EXE has the new parameter -credentialGUI. When set in console executables a graphical GUI is used for Get-Credential instead of console input.
      
      Greetings
      
      Markus
    • Markus,
      
      Thank you so much, but I cannot seem to get it to work. Yes, I am creating a console application without a GUI. Here's my command line for running ps2exe.ps1:
      
      Powershell -nop -ep ByPass "C:\Folder\ps2exe.ps1 'C:\Folder\Script.ps1' 'C:\Folder\Script.exe' -iconFile 'C:\Folder\Icon.ico' -title 'Script' -description 'Script' -product 'Script' -company 'Company' -version '1.0.0.0' -credentalGUI -runtime40"
      
      It still comes up in the console window itself as:
      
      Windows Powershell credential request
      Enter your credentials
      User name:
      
      And not the typical graphical prompt that allows the user to know that its a sercure prompt. Perhaps it's one of the other options I'm choosing? I tired it without -runtime40 and the same results.
      
      Many thanks,
      
      Charlize
    • Hello Charlze V,
      
      there is a typo in the "updates" section of this web page:
      The parameter is -credentialGUI, not -credentalGUI.
      
      Sorry for that, I will correct the description soon
      
      Greetings
      
      Markus
    • Markus,
      
      You rock! Works like a charm. Thank you so very much! Just in time to get this project out.
      
      Keep being awesome!
      
      Charlize
  • Error when calling ps2exe.ps1 inside other.ps1 file!
    6 Posts | Last post June 11, 2018
    • Hi Markus!
      
      I try to call ps2exe.ps1 in other.ps1 file by using & operator:
      & $ps2exe $inputFile $outputFile
      & $ps2exe $inputFile $outputFile -noConsole:$Null
      And some other calling method.
      I always see the compiling success (Output file $outputFile written) ouput in console follow the error below:
      
      The property 'Location' cannot be found on this object. Verify that the property exists.
      At D:\Powershell scripts\PS2EXE-GUI\ps2exe.ps1:261 char:2
      +     $referenceAssembies += ([System.AppDomain]::CurrentDomain.GetAsse ...
      +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
          + FullyQualifiedErrorId : PropertyNotFoundStrict
      
      Only calling $ps2exe with -noConsole parameter is not generates the error:
      & $ps2exe $inputFile $outputFile -noConsole
      
      Can I manual fix this?
      
      Thanks very much for your great script.
    • How to fix this error?
      
      Sorry, my english is not good.
    • Hello Minh Cường,
      
      what program do you use to run the script?
      
      There is a bug in PS2EXE that leads to this error. This error should not lead to any further problem. I will fix it in the next version of PS2EXE.
      
      Greetings
      
      Markus
      
    • Hi Markus.
      
      I'm just calling PS2EXE.ps1 from a simple OTHER.ps1 wrapper on Powershell console, did not import to any program yet.
      
      On next version if you are adding a parameter option to not writing *.config file that will be great :D
      
      I don't like to modify your PS2EXE script so I made a .ps1 wrapper to customize some of my need.
      
      Greetings.
      MC
    • Hello Minh Cường,
      
      the new version v0.5.0.11 of PS2EXE released today has fixed the error "The property 'Location' cannot be found on this object".
      Additionally there is a new parameter -noConfigfile that suppresses generation of the config file (that is unnecessary in most cases).
      
      Greetings
      
      Markus
    • Thanks very much for your script, Markus :3
      
      Greetings
      MC
  • Write-Progress, color of progress bar
    3 Posts | Last post June 11, 2018
    • Hi
      
      When using write-progress in PowerShell script and converting til exe the progress bar indicator gets blue color insted of green as in PowerShell. How can i change this?
      
      Greetings,
      Nils
      
    • Hello Nilzy,
      
      I use the standard color for progress controls to display the progress bar. But you are right, there should be a choice to choose the colors.
      
      It will take some time, but I will implement this in the next version of PS2EXE.
      
      Greetings
      
      Markus
    • Hello Nilzy,
      
      the new version v0.5.0.11 of PS2EXE allows to set the progress bar color in -noConsole mode, e.g.:
      $Host.PrivateData.ErrorForegroundColor = "Green"
      
      But only if visual styles are not enabled.
      
      Greetings
      
      Markus
101 - 110 of 174 Items