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


  • Run executable as a service
    2 Posts | Last post November 13, 2018
    • Dear Markus, excellent piece of work..!
      
      Application .exe works like a dream in console mode (GUI not required).
      
      Wondered if there's anything special needed to run .exe as a service..?
      
      Cheers, Simon
      (I tried, wouldn't start, not surprised)
      
      
    • Hello Msgwrx,
      
      there are some special requirements for a process that is supposed to be used as a service. Those are not implemented in PS2EXE.
      
      Maybe you can compile a script that is capable to be run as a service, e.g. the script from https://msdn.microsoft.com/en-us/magazine/mt703436.aspx might work wth some customizings.
      
      Greetings
      
      Markus
  • Retrieve exe name
    2 Posts | Last post October 27, 2018
    • Hello Markus,
      
      While I'm running the .exe file, is there a way to retrieve its actual name?
      
      I'd like copy the .exe file to a specific location at the end of the process.
      But if the .exe was renamed before running, [Copy-Item ".\MyFile.exe" "$Specific_Locaction"] won't work. (I use runtime20)
      
      Thanks.
    • Hello AG_G1,
      
      when I didn't forget one you have three methods to get the name of the executable:
      
      1. [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName
      retrieves the name of the executable including the full path
      
      2. [Environment]::GetCommandLineArgs()[0]
      retrieves the name of the executable most of the times including the full path
      
      3. [System.Diagnostics.Process]::GetCurrentProcess().ProcessName
      retrieves the name of the executable without path and without the extension ".exe"
      
      
      When called in a not compiled script the name of the powerShell is returned.
      
      
      Greetings
      
      Markus
      
      
  • ActiveDirectory module on network share
    2 Posts | Last post October 23, 2018
    • Hi
      
      I just ran into something peculiar that I think must be a bug.
      
      Created an exe with the following options~
      .\ps2exe.ps1 -inputFile $InputFile -outputFile $outputFile -noConsole -iconFile $iconFile -title $title -description $description -company $company -version $version -noConfigFile
      
      It opens up a simple Windows form with two textboxes and a run button.
      The run button basicly runs the following get users info and export to csv~
      	Get-ADUser -Filter * -Properties * -SearchBase $SearchOU | `
      	where {(Get-Date).AddDays($InputDays) -le $_.whenCreated } | `
      	select sAMAccountName, name, mail, title, division, department, whenCreated | `
      	
      	Export-Csv -Path $ExportCSVPath -Encoding UTF8 -NoTypeInformation
      
      The exe file will run perfectly anywhere on the C:\ drive, but if you have a mounted network drive, in our case Z:\ Import-module ActiveDirectory will fail to load with the following error message "Unable to contact the server. This may be because this server does not exist, it is current down, or it does not have the Active directory Web Service running.
      
      
    • Hello Bjørn,
      
      I tried your code sample on a local drive and a mounted drive: it worked fine in both cases.
      
      Have you checked if there is a problem with elevation (mounted drives are in general not visible in an elevated process)? Do you have AppLocker or Software Restriction Policies activiated that may prevent your script from running? Is your script running in PowerShell Constrained Language Mode? Do you have Share Hardening activated on the server that serves the mounted drives?
      
      Greetings
      
      Markus
      
      
  • Ohne Progress zu verwenden, poppt ein leeres Fenster mit dem Titel progress auf
    3 Posts | Last post October 21, 2018
    • I wrote a script that is displaying it's own two forms. If I run the script in Powershell ise everything works like expected, no output is written into the console. If I compile it with a console output, it works, too. BUT if I compile it with -noconsole, a window pops up several times very shortly - like a blinking. Using a screen shot program I discovered, that it is an empty window with the title progress. I am not using ANY progress related function.
      
      Is this a bug? I am using Windows 10 1809. How can I prevent this window flickering?
      
    • Hello CHBWien,
      
      when modules are loaded progress bars are displayed in powershell. In console mode they may appear and disappear so fast that you do not notice them.
      
      Try preventing any progress bar with the following command at the beginning of your script:
      
      $ProgressPreference = 'SilentlyContinue'
      
      Greetings
      
      Markus
      
    • Hi Markus,
      
      great advice. Works like a charm.
      
      Never realized, that progress bars appear on their own...
      
      THX!
      
      Christian
  • Reading from registry
    3 Posts | Last post October 17, 2018
    • Hi,
      
      I've got a PowerShell script which writes/reads from registry.
      
      write to registry:
      New-ItemProperty -Path $global:registryPath -Name $name -Value $global:deadline -PropertyType String -Force | Out-Null
      
      writes a date to reg value "ignoreTo"
      
      read from registry:
      $ignoreTo = (Get-ItemProperty $global:registryPath | Select-Object -ExpandProperty ignoreTo | Out-String) -replace "`n|`t|`r",""
      
      $ignoreTo (e.g. 17.10.2018) is a date which gets compared against $today (e.g. 16.10.2018)
      
      if ($today -gt $ignoreTo){
      ...
      }
      
      Both parts are working when I run the script as PowerShell. When I convert it to exe, the read part (or the comparision) doesn't, the if-condition allways runs.
      
      Any ideas where to start?
      
      Thx,
      Tony
      
    • I converted with:
      
      .\ps2exe.ps1 -noconsole -inputfile D:\PS\Check_DA_VPN\check_status.ps1 -outputfile D:\PS\Check_DA_VPN\UpdatePopup.exe –noconfig
    • Hello t_ny,
      
      your code fragment works fine for me (in one script). But I do not know how you get and convert your date values.
      
      Can it be that you try to use global variables to hand a value to different scripts? Compiled scripts do not know global variables, they only know variables that are defined in the executable.
      
      Greetings
      
      Markus
  • $MyInvocation - ScriptPath not returning correct path
    5 Posts | Last post October 03, 2018
    • I am running script from following location
      C:\Users\testuser\Downloads\PS2EXE-GUI\FIleShare
      
      IN this location I have one file called i.e. "Assessment.xml"
      
      As you suggested I used following
      if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript")
      { $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition }
      else
      { $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) }
      
      Then
      
      [xml]$xmlParameterAttribute = Get-Content "$ScriptPath\Assessment.xml"
      
      Without compling this code it is working fine, $scriptpath is correctly show path as mentioned above.
      
      But when I compile the code and run the code, it is coming as "c:\asessment.xml" instead of "C:\Users\testuser\Downloads\PS2EXE-GUI\FIleShare\asessment.xml".
      
      Am I missing anythig?
      
      I also used script path as 
      if ($hostinvocation -ne $null)
      {
           $ScriptPath=Split-Path $hostinvocation.MyCommand.path
      }
      else
      {
           $ScriptPath=Split-Path $script:MyInvocation.MyCommand.Path
      }
      
      But no luck, not sure what I am missing here.
      
      Avian
    • Hello Avian,
      
      I used the snippet you posted to check the issue. In my tests everything worked fine.
      
      The variable "$hostinvocation" is no standard variable, may you tell what version of PowerShell and Environment/Frameworks you use?
      
      Greetings
      
      Markus
    • HI Markus
      
      I am testing in PowerShell version 2.0.
      
      Surprisingly if I run as script it works, but when I run as exe it wont work.
    • Hallo Avian,
      
      I made a test on virtual machine with Windows XP and PowerShell 2.0, still everything works fine. Are you sure there is no typo in your script?
      
      
      Greetings
      
      Markus
    • Hello Avian,
      
      I got it. When you call the compiled script in a cmd.exe (and not in Powershell) without providing a path, [Environment]::GetCommandLineArgs()[0] returns $NULL.
      
      Please use the following code to prevent this (I updated the "Remarks" section of this web page too):
      
      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 = "." } }
      
      
      Greetings
      
      Markus
      
  • Getting strange parsing errors running after compilation?
    2 Posts | Last post September 15, 2018
    • Something in my script seems to be trigger runtime compilation errors after the exe is created.
      
      I'm guessing it's an issue in the encoding, or possibly special characters surviving the extraction from exe process?
      
      My script is here:  https://github.com/keylimesoda/MaddenToCSV
      
      Output when running exe is parsing errors at line 90, line 224, etc.
    • Hello Ric,
      
      I compiled your script but running does not succeed because of the usage of the variables $PSSCriptRoot and $myInvocation.MyCommand.Definition which are not present in compiled scripts (as they are no scripts anymore).
      
      See my explanation in the REMARKS section of this web page. Maybe that helps you.
      
      Greetings
      
      Markus
  • Get-Credential not returning $null when cancelled
    5 Posts | Last post September 11, 2018
    • Hi,
      Really great script! Had no problems until I tried to work with Get-Credential. I store a Password as an XML file. If the user accidently clicked the "Change Credentials" Button, he should be able to abort by clicking "cancel". However, the Output is not equal to $null...
      I poked around in the script a bit, but i couldn't fix the problem myself.
      Do you know where/why this happens?
      
      Thank you & Greetings
      Matthias
    • PS:
      This is the code:
      
      while ($true) {
              $Creds = (Get-Credential -User $env:USERNAME -Message "Please enter your Username and Password:")
              Write-Host "Validating..."
              if (($null -ne $Creds -and $Creds.GetNetworkCredential().password -match "^[0-9]{4,8}$") -or ($null -eq $Creds)){
                  return $Creds
              }
          }
    • Hello Matthias,
      
      I found the bug in PS2EXE. Quiet easy to correct, but I have to release a new version of PS2EXE. I will do this soon.
      
      Greetings
      
      Markus
      
    • Hello Matthias,
      
      I released the new version 0.5.0.13 of PS2EXE today that returns $NULL correctly when aborting the credential window.
      
      Greetings
      
      Markus
      
    • Hi Markus,
      
      Thank you for your quick response, works great!
  • Output from called vbs
    2 Posts | Last post August 17, 2018
    • Hi,
      I'm calling a vbs file though
      Invoke-Command -ScriptBlock { cscript "file.vbs"}
      
      In "console" mode, is there a way to get the standard output from file.vbs?
      Without "compiling" the ps1, i see the output from the vbs.
      
      Thanks, Nestor.
    • Hello Nestoter,
      
      I tried your sample code and got the Standard output of a vbs file shown in the compiled script.
      
      May you have an other error? Can it be your vbs file is not found since you don't supply a path to it?
      
      Greetings
      
      Markus
  • Included ps1 files
    3 Posts | Last post August 07, 2018
    • Hi,
      
      Works almost perfectly for what I need, just 1 question:
      
      Is there a way for the script to automatically add the code from imported scripts within the main script?
      
      I.e. I have a functions.ps1 file that gets imported at the top of the main file. This file will also import ps1 files depending on the function being called. This is being include via the following line:
      
      . "..\Includes\functions.ps1"
      
      If I leave this line in, I get an error stating that the command is not recognised.
      
      Any ideas?
      
      Thanks,
      Joe
    • Hello Joe,
      
      dot sourcing works fine with PS2EXE. As you are using a relative path please check that the current directory is what you expect it to be.
      
      You might use a path relative to the compiled script with:
      
      f ($MyInvocation.MyCommand.CommandType -eq "ExternalScript")
      { $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition }
      else
      { $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) }
      . "$Scriptpath\..\Includes\functions.ps1"
      
      (see "Remarks" sction for an explanation)
      
      Greetings
      
      Markus
      
    • Hi Markus,
      
      Thank you for your response, I actually already saw that piece of code, and was using it. For anyone that may have the same issue as I was, I created a script called "combine.ps1", with the following code:
      
      $includes = @()
      $includes = "..\Includes\file-01.ps1","..\Includes\file-02.ps1","..\Includes\file-03.ps1"
      Clear-Content .\complete-script.ps1
      
      Foreach ($include in $includes) {
      	$content = Get-Content $include | Where { $_ -notmatch "^\." }
      	$content = $content | Where { $_ -notmatch "^\# SIG" }
      	Add-Content .\complete-script.ps1 $content
      }
      
      .\PS2EXE-GUI\ps2exe.ps1 -inputFile ".\complete-script.ps1" -outputFile ".\complete-script.exe" -noConfigFile -credentialGUI
      Remove-Item ".\complete-script.ps1" -Force
      
      
      It's not ideal, as you have to specify the files in the array in the same order as what they appear in the script, but gets the job done.
      
      An improvement to this would be to add an "If" statement that finds the lines starting with "." and then automatically import that script in to "complete-script.ps1" file. Obviously, you would need to search recursively for dot sourced scripts to import...
      
      Thanks,
      Joe
81 - 90 of 171 Items