Skip to content

Commit 395a52d

Browse files
authored
Initial upload
1 parent e2eae72 commit 395a52d

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

PS2EXE-GUI/README.md

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# PS2EXE-GUI: "Convert" PowerShell Scripts to EXE Files with GUI
2+
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.
3+
4+
Since Technet Gallery will be closed, now here.
5+
6+
See Script Center version: [PS2EXE-GUI: "Convert" PowerShell Scripts to EXE Files with GUI](https://gallery.technet.microsoft.com/PS2EXE-GUI-Convert-e7cb69d5).
7+
8+
Author: Markus Scholtes
9+
10+
Version: v0.5.0.20
11+
12+
Date: 2020-04-19
13+
14+
All of you know the fabulous script PS2EXE by Ingo Karstein you can download here: [PS2EXE : "Convert" PowerShell Scripts to EXE Files](https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-Convert-PowerShell-9e4e07f1).
15+
16+
Unfortunately Ingo seems to have stopped working on his script so I overworked his script with some error fixes, improvements and output support for non-console WinForms scripts (parameter -noConsole to ps2exe.ps1).
17+
18+
19+
Module based version available now on Powershell Gallery, see here (https://www.powershellgallery.com/packages/ps2exe) or install with Install-Module PS2EXE
20+
21+
Project page on github is [here](https://github.com/MScholtes/PS2EXE).
22+
23+
24+
### Update v0.5.0.20 - 2020-04-19
25+
Application.EnableVisualStyles() as default for GUI applications
26+
27+
new parameter -noVisualStyles to prevent this
28+
29+
30+
Full list of changes and fixes in Changes.txt.
31+
32+
### Includes Win-PS2EXE, a small graphical front end for PS2EXE.
33+
34+
Not all parameters are supported, requires .Net 4.x. C# WPF application. With drag'n'drop for file names. Has to be placed in the same directory as ps2exe.ps1. Source code and .Net 3.5x version are here: (https://github.com/MScholtes/Win-PS2EXE).
35+
36+
![Screenshot](Screenshot-Small.jpg)
37+
38+
39+
## GUI support:
40+
41+
- expanded every output and input function like Write-Host, Write-Output, Write-Error, Out-Default, Prompt, ReadLine to use WinForms message boxes or input boxes automatically when compiling a GUI application
42+
43+
- no console windows appears, real windows executables are generated
44+
45+
- just compile with switch "-noConsole" for this feature (i.e. .\ps2exe.ps1 .\output.ps1 -noConsole)
46+
47+
- see remarks below for formatting of output in GUI mode
48+
49+
![GUI Output](GUI Output.jpg)
50+
51+
## Examples:
52+
Compile all of the examples in the Examples sub directory with
53+
54+
```powershell
55+
BuildExamples.bat
56+
```
57+
58+
Every script will be compiled to a console and a GUI version (-NoConsole).
59+
60+
61+
## Remarks:
62+
63+
### GUI mode output formatting:
64+
65+
Per default output of commands are formatted line per line (as an array of strings). When your command generates 10 lines of output and you use GUI output, 10 message boxes will appear each awaitung for an OK. To prevent this pipe your command to the comandlet Out-String. This will convert the output to a string array with 10 lines, all output will be shown in one message box (for example: dir C:\ | Out-String).
66+
67+
### Config files:
68+
69+
PS2EXE create config files with the name of the generated executable + ".config". In most cases those config files are not necessary, they are a manifest that tells which .Net Framework version should be used. As you will usually use the actual .Net Framework, try running your excutable without the config file.
70+
71+
### Password security:
72+
Never store passwords in your compiled script! One can simply decompile the script with the parameter -extract. For example
73+
```powershell
74+
Output.exe -extract:C:\Output.ps1
75+
```
76+
will decompile the script stored in Output.exe.
77+
78+
### Script variables:
79+
80+
Since PS2EXE converts a script to an executable, script related variables are not available anymore. Especially the variable $PSScriptRoot is empty.
81+
82+
The variable $MyInvocation is set to other values than in a script.
83+
84+
You can retrieve the script/executable path independant of compiled/not compiled with the following code (thanks to JacquesFS):
85+
86+
```powershell
87+
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript")
88+
{ $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition }
89+
else
90+
{ $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) }
91+
```
92+
93+
### Window in background in -noConsole mode:
94+
95+
When an external window is opened in a script with -noConsole mode (i.e. for Get-Credential or for a command that needs a cmd.exe shell) the next window is opened in the background.
96+
97+
The reason for this is that on closing the external window windows tries to activate the parent window. Since the compiled script has no window, the parent window of the compiled script is activated instead, normally the window of Explorer or Powershell.
98+
99+
To work around this, $Host.UI.RawUI.FlushInputBuffer() opens an invisible window that can be activated. The following call of $Host.UI.RawUI.FlushInputBuffer() closes this window (and so on).
100+
101+
The following example will not open a window in the background anymore as a single call of "ipconfig | Out-String" will do:
102+
103+
```powershell
104+
$Host.UI.RawUI.FlushInputBuffer()
105+
ipconfig | Out-String
106+
$Host.UI.RawUI.FlushInputBuffer()
107+
```

0 commit comments

Comments
 (0)