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: https://github.com/MScholtes/TechNet-Gallery

PS2EXE-GUI.zip
 
 
 
 
 
4.7 Star
(38)
36,815 times
Add to favorites
7/11/2020
E-mail Twitter del.icio.us Digg Facebook
  • Flagged by Anti Virus
    2 Posts | Last post July 24, 2019
    • After compiling using the tool using the GUI version my EXE's are being flagged by ESET Antivirus as a trojan. Compiling through the command line does not cause this.
    • Hello Cole,
      
      I uploaded a file compiled directly with the script PS2EXE.ps1 and a script compiled using WinPS2EXE to VirusTotal. The ESET antivirus rated both executables "unsuspicious".
      
      Greetings
      
      Markus
  • 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
61 - 70 of 184 Items