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
(35)
33,471 times
Add to favorites
7/1/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • How do you detect the run path automatically?
    2 Posts | Last post July 10, 2019
    • When the powershell script is compiled the normal principles for automatically determining the run directory no longer seem to working. For example if a mypowershellscript.exe is in c:\temp\mypowershellscript.exe how would I get the parent directory of the exe? As the $MyInvocation don't seem to be populated.
    • Hello CASWEBSI,
      
      please see the description in the Remarks section of this web page ("Script variables:").
      
      Greetings
      
      Markus
  • Suggestion
    6 Posts | Last post July 01, 2019
    • Hello,
      
      I have a suggestion:
      
      Add this to the manifest xml
      
      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
          <!--The ID below indicates application support for Windows Vista -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
          <!--The ID below indicates application support for Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
          <!--The ID below indicates application support for Windows 8 -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
          <!--The ID below indicates application support for Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
          <!--The ID below indicates application support for Windows 10 -->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
        </application>
      </compatibility>
      
      This will avoid "Program Compatibility Assistant" Message (This program might not have installed correctly) popping up after exiting the executable, if its file/product name contain any of these words:
      Setup, Install, Installer, Installation, Uninstall
      
    • Hello Romeo Montague,
      
      I will do some Research About this Topic.
      
      Greetings
      
      Markus
    • Hello Romeo,
      
      seems to be useful to make a parameter for this. I will implement it in the next version.
      Maybe you can work around until then with the option -x64 if 64 bit is applicable for you.
      
      Greetings
      
      Markus
      
    • Hello Markus,
      
      thank you, but I had already modified a previous version, should have posted it right away. There is a manifest xml included by default which isn't in the ps2exe.ps1, so I took it and added the above snippet.
      
      $reqAdmParam = ""
      if ($requireAdmin)
      {
      	$execLvl = "requireAdministrator"
      }
      else
      {
      	$execLvl = "asInvoker"
      }
      $win32manifest = "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>`r`n<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">`r`n  <!--<assemblyIdentity version=""1.0.0.0"" name=""MyApplication.app""/> -->`r`n  <trustInfo xmlns=""urn:schemas-microsoft-com:asm.v2"">`r`n    <security>`r`n      <requestedPrivileges xmlns=""urn:schemas-microsoft-com:asm.v3"">`r`n        <requestedExecutionLevel level=""$execLvl"" uiAccess=""false""/>`r`n      </requestedPrivileges>`r`n    </security>`r`n  </trustInfo>`r`n  <compatibility xmlns=""urn:schemas-microsoft-com:compatibility.v1"">`r`n    <application>`r`n      <!--The ID below indicates application support for Windows Vista -->`r`n        <supportedOS Id=""{e2011457-1546-43c5-a5fe-008deee3d3f0}""/>`r`n      <!--The ID below indicates application support for Windows 7 -->`r`n        <supportedOS Id=""{35138b9a-5d96-4fbd-8e2d-a2440225f93a}""/>`r`n      <!--The ID below indicates application support for Windows 8 -->`r`n        <supportedOS Id=""{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}""/>`r`n      <!--The ID below indicates application support for Windows 8.1 -->`r`n        <supportedOS Id=""{1f676c76-80e1-4239-95bb-83d0f6d0da78}""/>`r`n      <!--The ID below indicates application support for Windows 10 -->`r`n        <supportedOS Id=""{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}""/>`r`n`r`n    </application>`r`n  </compatibility>`r`n</assembly>"
      $win32manifest | Set-Content ($outputFile+".win32manifest") -Encoding UTF8
      $reqAdmParam = "`"/win32manifest:$($outputFile+".win32manifest")`""
      
      
    • Hello Romeo,
      
      you are too late with this comment. The new version of PS2EXE with the parameter -supportOS is ready and will be published on Monday.
      
      Greetings
      
      Markus
    • Hello Romeo,
      
      I released the new version V0.5.0.16 today that addressing your issue with the new parameter -supportOS.
      
      Greetings
      
      Markus
  • Add a parameter "-noNamedParams" to ps2exe.ps1
    5 Posts | Last post June 30, 2019
    • I created an enhancement for ps2exe:
      
      -noNamedParams = disable interpreting parameters in powershell style, means arguments will be passed directly
      
      If this parameter is set the part for "{ // parameter in powershell style" is commented, means "named parameter found" will be ignored, means all parameters will be handled as "unnamed" and passed directly to the original .ps code. This means especially that not $True or $False processing is done.
      The purpose is mainly if you want to call an external .exe or .cmd (e.g. with Start-Process  -ArgumentList …) that cannot deal with the powershell style parameters and you might pass the original parameters directly.
      
      Unfortunately I cannot upload my contribution because I am getting the message:
      
      "Sorry, you don't have privilege to upload a sample."
      
      
      
    • Hello obrain17,
      
      I have to admit I don't really understand your question. 
      What is "argument passed directly"? PS2EXE is calling a Powershell script, so obviously there is no "direct" passing of parameters but always a "passing to Powershell".
      Why don't you set your parameters in quotes to pass them unchanged?
      
      Greetings
      
      Markus
      
    • Hello Markus,
      
      I do not call the program myself. In this case of course I could adapt the arguments, set them in quotes .etc..
      
      The purpose of the "-noNamedParams" option is when you want to write kind of a hook-program or replacement = an exe file that has the same  name of an already exiting one. It gets called, then does this and that, and afterwards it may call the original .exe passing the original arguments unchanged.
      
      Even if I only write a .ps1 that displays the $args on the console, this .ps1 will show them all correctly but a "ps2exe" compiled .exe would show $True" for empty arguments, remove some ":" from pathname, etc.
      
      But with my new "-noNamedParams" switch the .exe will behave exactly as the .ps1. 
      
      Best regards,
      Rainer
    • Hello obrain17,
      
      I understand now. But I guess I will not implement this feature for two reasons. First the executables generated by PS2EXE shall behave as closest as possible like the original script. This switch would prevent this. Second, your request seems to be a very special request. I may change my mind if there are other people requesting this.
      
      Greetings
      
      Markus
    • Hello Markus,
      
      You are right, it is a very special request. For me it worked perfectly, but I understand I might be the only one needing this. And I already have it :-)
      
      As a last info for those who might been interested, here a part of a .ps1 script hat is making use of the feature of passing the parameters directly to another program:
      
      foreach($u in $Args) 
      {
        $v=[string]$u
        $prm += $v + ' '
      }
      
      $process = Start-Process -Filepath $proc -ArgumentList $prm
      
      Best regards,
      Rainer
  • Nested scripts
    2 Posts | Last post June 27, 2019
    • I have a master script which in turn calls the other ps1 scripts in different folders. How can I convert all these scripts into a single exe file?
      The current tool is good for 1 to 1 conversion. But am unable to use it in my scenario.
    • Hello ShettyPrashant,
      
      I think I cannot fulfill the wish you have. There are to many things PS2EXE would have to determine or could not predict: the path to a sub script might be evaluated at runtime, variables might have a (sub) script scope, how to handle parameters to sub scripts.
      
      Maybe a tool that generates self extracting archives would be better for you.
      
      Greetings
      
      Markus
      
  • Mouse wheel scrolling in console
    9 Posts | Last post June 07, 2019
    • Hello,
      
      is there any way to enable mouse wheel scrolling in console mode?
      
      Thanks in advance.
      
    • Hello Romeo Montague,
      
      I tested it. Mouse wheel scrolling works fine for me in console mode. Can you tell more about the script and situation where scrolling does not work?
      
      Greetings
      
      Markus
      
    • Hello Markus Scholtes,
      
      I have tried the following code with v0.5.0.15 using the BuildExamples:
      
      for ($i=1; $i -le 350; $i++) {$i,"`n"}
      $input = [System.Console]::ReadKey("NoEcho")
      
      I am using Windows 7, PS version is 5.1
      
    • Hello Romeo Montague,
      
      I guess it has nothing to do with PS2EXE but with the buffer settings of your command prompt (cmd.exe).
      To check this start a command prompt, open the menu (maybe with a right click on the title bar) and select "Defaults". Go to the tab "Layout" and check if the value for "Height" in the section "Screen Buffer size" is high enough to allow scrolling.
      
      Greetings
      
      Markus
      
    • Hello,
      
      in the defaults the buffer size height is 300, in properties it is 3000.
      When running the above code in cmd scrolling works, but not in compiled exe.
      Scrolling in exe works when I enable the quick edit mode in options tab.
      Would it be possible to enable this option through the script somehow?
      
      
      
      
    • Hello Romeo Montague,
      
      this is quite confusing. I guess the reason is that cmd.exe tries to determine whether scrolling has to be enabled or not (see here: https://superuser.com/questions/1404238/enable-scroll-wheel-to-scroll-command-prompt-while-its-running-applications) and is guessing wrong here.
      
      I do not know a way to change the "quick edit" setting in a script for the running shell.
      
      Greetings
      
      Markus
    • Hello Markus Scholtes,
      
      apparently the scrolling of unfocused window (mentioned in the link) is Windows 10 feature, see here https://stackoverflow.com/questions/44735362/control-mousewheel-event
    • Hello Markus Scholtes,
      
      thanks for your support!
      I found how to enable the "quick edit" mode from the script, see first answer here: https://stackoverflow.com/questions/30872345/script-commands-to-disable-quick-edit-mode
      And modifying the above with the information from the answer here: https://stackoverflow.com/questions/23666035/how-to-make-readconsoleinput-notice-mouse-events-when-program-is-running-from
      allows to enable mouse wheel scrolling without quick edit mode.
    • Hello Romeo Montague,
      
      it's a good thing you found a solution. Unfortunately I can't help with PS2EXE in this situation.
      
      Greetings
      
      Markus
  • Invocation Filename
    6 Posts | Last post June 05, 2019
    • Any suggestions for getting the filename of invocation? 
      
      For example, in ISE or Console I would use $MyInvocation.MyCommand.Definition, which would provide the fullpath+invocation script name.
      
      This doesn't appear to work with a complied EXE though, any suggestions? 
    • The answer is in the included Readme.txt
    • … and on this web page in the "Remarks" section :-)
      
      Greetings
      
      Markus
    • That provides the working directory (which I've already incorporated) but not the filename of the executing script.
      
      For example, convert test.exe. User renames it to Test2.exe. $ScriptPath will give you the path of invocation, but not what the originating file was.
      
      I understand PS2EXE packages its own console, so I'm just wondering if this is even possible.
    • Appears that using $(([Environment]::GetCommandLineArgs()[0])) from that same code block works for this.
    • Hello cpierr03,
      
      sorry, I forgot to clearify:
        $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) 
      gives you the parent directory to the executable (and NOT the working directory), so obviously 
        [Environment]::GetCommandLineArgs()[0]
      returns the executable's full path.
      
      Greetings
      
      Markus
  • Getting unhandled Exception : System.IO.FileNotFoundException
    5 Posts | Last post June 04, 2019
    • Hello,
      
      I am getting exception on some systems (I think only on PS Version 2.0). Please find the complete exception below:
      Unhandled Exception : System.IO.FileNotFoundException: Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. at ik.PowerShell.PS2EXE.Main(String[] args)
      
      Can you please help me to fix this. I cannot update the PS Version due to some norms.
      
      Thanks.
    • I tried to create the exe on PS version 2.0 system and it got created with below message.
      
      WARNING: No .Net 3.5 compiler found, using .Net 2.0 compiler.
      WARNING: Therefore some methods are not available!
      
      But, it is not responding after clicking any buttons of the aplication.
    • Hello Ashutosh Tripathi 14,
      
      when I interpret the errors Right you are using .Net 2 on the computer. PowerShell V2 is still supported by Microsoft, but only with .Net 3.5. So I do no tests against .Net 2 for a longer time. Please upgrade to .Net 3.5x or .Net 4.x
      
      Greetings
      
      Markus
    • Thank you Markus for your response. I can't upgrade the .Net framework, because our hosted application on these servers has a dependency on .Net framework 2.0. 
      Is there any other way you can suggest?
      
      Regards,
      Ashutosh
    • Hello Ashutosh Tripathi 14,
      
      I'm sorry to say that I can't help you, PS2EXE would have to be reengeneered to work for you. 
      
      It's not only that I have no developing environment with .Net 2, too much had to be changed in PS2EXE (not only calls to DLLs would have to be replaced but functions need to be rewritten with the functional scope of .Net 2).
      
      I can't afford this.
      
      Greetings
      
      Markus
  • icon for progress bar in task bar
    2 Posts | Last post June 01, 2019
    • A few months ago I asked about an icon for the progress bar in the task bar, I have found a way to do it though I would share with you
      
      this.Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().Location);
      
      add this line where you declare the parameters of the progress bar form. it will extract the icon from the exe and us it as the icon for the progress bar
    • Hello jackofalltech,
      
      thank you for this hint but it is already implemented in the newest version of PS2EXE.
      
      Greetings
      
      Markus
  • POWERSHELL VERSION IS UNKNOWN!
    8 Posts | Last post May 13, 2019
    • Hi, I've been waiting for the update.
      But, ver 0.5.0.15 dosen't work on Powershell 5.
      
      The judgment of the version has changed, but why?
      
      ver 0.5.0.15 - line 74
      if($PSVersionTable.PSVersion.Major -eq 4) {
                                         ~~~
      ver 0.5.0.14 - line 84
      if ($PSVersionTable.PSVersion.Major -ge 4)
                                          ~~~
      
      
    • sorry. I saw the original file.
      The anti-virus software deleted the file and misunderstood it.
    • Anti-Virus Software is Kaspersky(KSOS6).
      I checked where it was not good.
      
      Line 371
      $scriptInp = [STRING]::Join("`r`n", $content)
      -> threats
      $scriptInp = [string]::Join("`r`n", $content)
      -> safe
      
      I do not know why ...
    • Hello T.Takashi,
      
      thank you very much for your advice. It is interesting that the detection/not detection depends on the case of the word "string". One could tell that this shows some weakness in the heuristic of the Kapersky engine :-)
      
      I sent the file to the Antivirus lab of Kaspersky for further investigation and correction.
      
      Greetings
      
      Markus
    • Hello T.Takashi,
      
      got an answer from Kapersky (that's fast): "Sorry, it was a false detection. It will be fixed."
      
      Thanks
      
      Markus
    • Thank you,  Markus.
      
      I look forward to it in the future!
      
      T.Takashi
      
    • Hello T.Takashi,
      
      Kaspersky did fix its virus engine, PS2EXE is no longer identified as a virus.
      
      Greetings
      
      Markus
    • Hello Markus,
      
      Kaspersky has been fixed.
      very fast!
      
      T.Takashi
  • Doesn't seem to work for me, don't know why
    9 Posts | Last post May 12, 2019
    • Hi, this is a very interesting tool for us but I can't get it to work.
      When I compile everything seems fine but when I then run the .exe like I do the .ps1 I get these errors that I don't understand. The powershell script runs fine.
      
      C:\abc>abc.exe settings.ps1
      ERROR: At line:632 char:41
      +  cat c:\abc\allvms1.list | %{$_ -replace ?Name : ?,??} | %{$_ -replac ...
      +                                         ~
      You must provide a value expression following the '-replace' operator.
      
      At line:632 char:42
      +  cat c:\abc\allvms1.list | %{$_ -replace ?Name : ?,??} | %{$_ -replac ...
      +                                          ~~~~~
      Unexpected token '?Name' in expression or statement.
      
      At line:632 char:71
      + ... bc\allvms1.list | %{$_ -replace ?Name : ?,??} | %{$_ -replace ?Name?, ...
      +                                                                  ~
      You must provide a value expression following the '-replace' operator.
      
      At line:632 char:72
      + ... ms1.list | %{$_ -replace ?Name : ?,??} | %{$_ -replace ?Name?,??} | % ...
      +                                                            ~~~~~~
      Unexpected token '?Name?' in expression or statement.
      
      At line:632 char:78
      + ... s1.list | %{$_ -replace ?Name : ?,??} | %{$_ -replace ?Name?,??} | %{ ...
      +                                                                 ~
      Missing argument in parameter list.
      
      At line:632 char:98
      + ... lace ?Name : ?,??} | %{$_ -replace ?Name?,??} | %{$_ -replace ?----?, ...
      +                                                                  ~
      You must provide a value expression following the '-replace' operator.
      
      At line:632 char:99
      + ... ame : ?,??} | %{$_ -replace ?Name?,??} | %{$_ -replace ?----?,??}> c: ...
      +                                                            ~~~~~~
      Unexpected token '?----?' in expression or statement.
      
      And that goes on for a while.
      
      Any help would be very welcome.
      
      Regards,
        Stefan
    • Hello StefanBPS,
      
      you have some non-ASCII apostrophs in your scripts like “Name : ”,“” (copy-and-paste-error form Word or a webbrowser?).
      PowerShell is nice if they appear in an ANSI encoded file, but PS2EXE converts the script internally to UNICODE. So you get an error then.
      
      Please replace the wrong apostrophs with the correct ones: ' or ". Then everything will be fine.
      
      Greetings
      
      Markus
      
    • Markus, that helped a lot, thank you.
      Could it be that I can't load the Veeam snapin for Powershell.
      
      This is my code:
      \\
      
      Add-PSSnapin VeeamPSSnapin
      
      if( -not $?)
      {
      Write-Output "$(Get-TimeStamp) restorevm function : error loading the the Veeam powershell snapin" | Out-file $tracefile -append
      mailandcleanup
      }
      \\
      
      And my trace files shows that the it's giving an error on the RC so it starts the mailandcleanup function.
      Is this a possible limitation of the PS2EXE? I felt like I was so close to having it work! :)
      
    • Oh, sorry, it gave that error because it was already loaded.
      
      The real problem is this part:
      
      ERROR: Cannot convert 'System.Object[]' to the type 'Veeam.Backup.Core.Infrastructure.CViDatastoreItem' required by parameter 'Datastore'. Specified method is not supported.
      
      
    • Hello StefanBPS,
      
      I guess I cannot help in this case since Veeam is a Commercial product I don not own. But it might be helpful if you post the command that leads to the error message.
      
      Greetings
      
      Markus
    • I understand, maybe you have an idea what the problem could be.
      I have this powershell script that I would really like to compile to .exe, it works fine in powershell and restores a VM, it doesn't work after it is compiled.
      
      
      Veeam needs some variables to be filled before the restore can start:
      
      $datastore = Find-VBRViDatastore -Server $abchost -Name ($abcdatastore)
      $resourcepool = Find-VBRViResourcePool -Server "$abchost" -Name "$abcresourcepool"
      $restorepoint = Get-VBRRestorePoint -Backup $job -Name $line | Select -Last 1
      
      This is what's in the variables at my test run with Powershell (I did a write-host)
      
      restorepoint is Veeam.Backup.Core.COib
      server is esx01.demo.local
      resourcepool is Veeam.Backup.Core.Infrastructure.CViResourcePoolItem
      datastore is STORE12_cpty_vol02_V3700demo
      vmname is Vyos05-abctmp
      <restore starts and works fine>
      
      This is what's in the variables at my test run with the compiled .exe (write-host again)
      
      restorepoint is Veeam.Backup.Core.COib
      server is esx01.demo.local
      resourcepool is Veeam.Backup.Core.Infrastructure.CViResourcePoolItem
      datastore is STORE12_cpty_vol02_V3700demo
      vmname is Vyos05-abctmp
      <restore error as seen below>
      
      but the restore command gives this error:
      
      ERROR: Cannot convert 'System.Object[]' to the type 'Veeam.Backup.Core.Infrastructure.CViDatastoreItem' required by parameter 'Datastore'. Specified method is not supported.
      
      
      Used restore command:
      
      restore command: Start-VBRRestoreVM –RestorePoint $restorepoint –Server $abchost -Resourcepool $resourcepool –Datastore $datastore -VMName "$line-abctmp" | Tee-Object -FilePath "c:\abc\logs\$line-vmrestorecommandoutput.log" -append
      
      Any help would be great, if not that's ok.
      
      Stefan
    • The problem seems to be the type of variables passed tot he Start-VBRRestoreVM command. Powershell has no problems with these and executes the restore but once you compile the powershell script it comes with the "ERROR: Cannot convert 'System.Object[]' to the type 'Veeam.Backup.Core.Infrastructure.CViDatastoreItem' required by parameter 'Datastore'. Specified method is not supported." error.
      
      I can't seem to work around this problem yet.
      
    • Hello StefanBPS,
      
      seems to me a similiar problem like the "apostroph issue". In the command line with Start-uVBRRestoreVM there are some "EN DASH" characters (ASCII code 0x96) instead of the regular "hyphen minus" (ASCII code 0x2d). Please copy the "minus" from –Datastore to the clipboard and use it to replace it with a correct minus.
      
      Did you copy commands from MS Word, this character is used there as a optional hyphen?
      
      Greetings
      
      Markus
    • This was it, you fixed it Markus.
      I'm so happy, I've been wanting to get this code into .exe for a while now and you made it possible.
      Thank you very much, I know these questions where very much powershell code related and not really related to your software so I'm extra grateful that you helped me like you did.
      Thanks again.
      
      Regards,
        Stefan
21 - 30 of 143 Items