1
0

Auto-commit: 2025-10-31 08:58:35

This commit is contained in:
David Wuibaille
2025-10-31 08:58:36 +01:00
parent 7d94414992
commit 7cc3011354
1088 changed files with 193455 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
@echo off
powershell -nop -ep ByPass "%~dp0BuildExamples.ps1"

View File

@@ -0,0 +1,13 @@
# Markus Scholtes 2017
# Create examples in subdir "Examples"
$SCRIPTPATH = Split-Path $SCRIPT:MyInvocation.MyCommand.Path -parent
ls "$SCRIPTPATH\Examples\*.ps1" | %{
."$SCRIPTPATH\ps2exe.ps1" "$($_.Fullname)" "$($_.Fullname -replace '.ps1','.exe')" -verbose
."$SCRIPTPATH\ps2exe.ps1" "$($_.Fullname)" "$($_.Fullname -replace '.ps1','-GUI.exe')" -verbose -noConsole
}
Remove-Item "$SCRIPTPATH\Examples\Progress.exe*"
Remove-Item "$SCRIPTPATH\Examples\ScreenBuffer-GUI.exe*"
$NULL = Read-Host "Press enter to exit"

View File

@@ -0,0 +1,469 @@
PS2EXE-GUI v0.5.0.18
Changes:
- fixed "unlimited window width for GUI windows" issue in ps2exe.ps1 and Win-PS2EXE
List of changes (line numbers are from PS2EXE-GUI v0.5.0.17):
lines 87 to 88 - adjusted version number and date
line 102 - adjusted version number
line 114 - adjusted version number
line 1110 - inserted screen size check
line 1192 - inserted screen size check
line 1202 - inserted screen size check
line 1207 - removed braces
line 1212 - inserted screen size check
line 1215 - removed braces
line 1217 - removed braces
line 1358 - inserted screen size check
line 2299 - adjusted version number
line 2567 - removed comment
PS2EXE-GUI v0.5.0.17
Changes:
- set -noConfigFile as default, introduced parameter -configFile
- created comment based help
- removed aliases %, ? and select with full commmandlets
- several smaller optimizations
List of changes (line numbers are from PS2EXE-GUI v0.5.0.16):
before line 1 - comment based help
lines 4 to 5 - new parameter -configFile
line 9 - adjusted version number
line 21 - adjusted version number
lines 28 to line 32 - moved to line 162
lines 34 to line 39 - moved to line 190
lines 44 to 70 - changed help text
lines 185 to 189 - inserted code for -configFile
lines 301, 303, 306, 312, 331, 332, 2484, 2494 - removed aliases
line 2197 - adjusted version number
lines 2501 - changed for new default -noConfigFile
PS2EXE-GUI v0.5.0.16
Changes:
- introduced parameter -noOutput to supress every standard output (incl. verbose and informational output)
- introduced parameter -noError to supress every error output (incl. warning and debug output)
- introduced parameter -supportos to use functions of newest Windows versions (execute [Environment]::OSVersion to see the difference)
List of changes (line numbers are from PS2EXE-GUI v0.5.0.15):
lines 1 to 4 - definition of new parameters
line 8 - adjusted version number
line 21 - adjusted version number
line 47 - expanded help text
lines 69 to 71 - expanded help text
line 148 - inserted code to check for valid parameters with -supportOS
line 199 - inserted support for -noOutput and -noError for Powershell V2
line 202 - inserted support for -supportOS for Powershell V2
line 333 - added code for supportedOS manifest
line 345 - inserted code for supportedOS manifest
line 1880 - added code for -noOutput
line 1890 - added code for -noOutput
line 1895 - added code for -noOutput
line 1900 - added code for -noOutput
lines 1906 to 1907 - added code for -noError
line 1910 - added code for -noError
line 1916 - added code for -noError
line 1920 - added code for -noError
line 1923 - added code for -noError
line 1928 - added code for -noOutput
line 1932 - added code for -noOutput
line 1937 - added code for -noOutput
line 1947 - added code for -noOutput
line 1950 - inserted code for -noError
line 1953 - added code for -noOutput
line 1958 - added code for -noOutput
line 1983 - added code for -noOutput
line 1987 - added code for -noOutput
lines 1993 to 1994 - added code for -noError
line 1997 - added code for -noError
line 2164 - adjusted version number
line 2405 - added code for -noError
line 2410 - added code for -noError
line 2487 - added code for supportOS
PS2EXE-GUI v0.5.0.15
Changes:
- introduction of graphical front end "Win-PS2EXE"
- parameter "output file" is not mandatory anymore, if target filename is not specified source filename is used with extension ".exe"
- check if output file has extension ".exe" or ".com"
- PS2EXE's own dialogs (Inputbox, Choicebox, Keypress and Progress form) use the application's icon if present
- replacement of Write-Host with Write-Output, Write-Warning and Write-Error (affected lines not listed below)
- cleanup of upper and lower case letters and white space (affected lines not listed below)
List of changes (line numbers are from PS2EXE-GUI v0.5.0.14):
line 8 - adjusted version number
line 41 - check for empty $outputFile removed
lines 108 to 110 - added code to handle empty $outputFile
line 121 - inserted code to check if $outputFile has extension ".exe" or ".com"
line 362 - safer query for empty content
line 1022 - inserted code to set application's icon for input box if present
line 1107 - inserted code to set application's icon for choice box if present
line 1234 - inserted code to set application's icon for keypress form if present
line 1285 - added code to set application's icon for progress form form if present
line 2140 - adjusted version number
PS2EXE-GUI v0.5.0.14
Changes:
- introduced parameter -longPaths to support .Net4.62 long paths
(requirements: 1. Windows 10, 2. "Long Path" policy set, 3. Compile with -longPaths, 4. the generated config file has to be in the same directory as the executable)
List of changes (line numbers are from PS2EXE-GUI v0.5.0.13):
line 4 - definition of new parameters
line 8 - adjusted version number
line 21 - adjusted version number
line 49 - expanded help text
line 76 - appended help text
line 156 - appended parameter checks for -longPaths
lines 315 to 325 - inserted new manifest configuration for -longPaths parameter
line 2120 - adjusted version number
line 2392 - appended config file configuration for -longPaths parameter
PS2EXE-GUI v0.5.0.13
Changes:
- Get-Credential returns $NULL on abort when compiled with -noConsole or -credentialGUI
- implemented $Host.UI.RawUI.FlushInputBuffer() in console mode
- $Host.UI.RawUI.FlushInputBuffer() in noConsole mode starts an invisible window to prevent further windows to be opened in the background
List of changes (line numbers are from PS2EXE-GUI v0.5.0.12):
line 8 - adjusted version number
line 21 - adjusted version number
line 183 - parameters -credentialGUI and -noConfigfile for powershell v2 too
lines 661 to 664 - implemented FlushInputBuffer() (flush input in console mode, invisible form in noconsole mode)
line 1688 - PromptForCredential returns null on abort in noconsole mode
line 1734 - PromptForCredential returns null on abort in noconsole mode
line 2096 - adjusted version number
PS2EXE-GUI v0.5.0.12
Changes:
- with -NoConsole the prompt for Read-Host is shown now for secure input
- updated help text
List of changes (line numbers are from PS2EXE-GUI v0.5.0.11):
line 8 - adjusted version number
line 21 - adjusted version number
lines 45 to 47 - expanded help text
line 1798 - passing prompt to InputBox now
line 2094 - adjusted version number
PS2EXE-GUI v0.5.0.11
Changes:
- fixed errors with redirection of error stream and input stream ("handle is invalid")
- $host.privatedata.ErrorForegroundColor to $host.privatedata.VerboseBackgroundColor set colors in console mode
(can someone shoot Microsoft in the knee for this strange undocumented implementation)
- $host.privatedata.ProgressForegroundColor set the color of the progress bar in noConsole mode (when visual styles are not activated)
- fixed error with failing reference to Consolehost.dll
- new parameter -credentialGUI to generate graphical GUI for Get-Credential in console mode
- new parameter -noConfigfile to suppress generation of config file
- smaller fixes
List of changes (line numbers are from PS2EXE-GUI v0.5.0.10):
line 4 - definition of new parameters
line 8 - adjusted version number
line 21 - adjusted version number
lines 49 to 73 - expanded help text
line 155 - changed information text
line 261 - fixed error with failing reference to Consolehost.dll
line 386 - implementation of -credentialGUI
line 596 - fixed error with redirection of input stream ("handle is invalid")
line 1195 - set color for progress bar including conversion from ConsoleColor to Drawing.Color
line 1199 to 1204 - removed redundant object generation
line 1240 - inserted setting progress bar color
line 1274 - inserted contructor for setting progress bar color
line 1327 - inserted functions to check for redirection
line 1334 - inserted variables for console colors
line 1540 - implementation of -credentialGUI
line 1731 to 1736 - optimized WriteDebugLine
line 1746 to 1751 - optimized WriteErrorLine and implemented error redirection
line 1800 - implemented setting progress bar color
line 1815 to 1820 - optimized WriteVerboseLine
line 1830 to 1835 - optimized WriteWarningLine
line 1859 - inserted ConsoleProxy and PrivateData (very strange things)
line 1903 - adjusted version number
line 1940 to 1970 - removed functions to check for redirection (expanded and moved to line 1327)
line 2037 - changed check for redirection
linie 2239 to 2247 - implementation of -noConfigfile
PS2EXE-GUI v0.5.0.10
Changes:
- Get-Credential is assuming a generic login so no "\user" is returned if domain name is not set
List of changes (line numbers are from PS2EXE-GUI v0.5.0.9):
line 8 - adjusted version number
line 21 - adjusted version number
line 463 - checks for PSCredentialTypes.Generic instead of PSCredentialTypes.Domain now
line 1903 - adjusted version number
PS2EXE-GUI v0.5.0.9
Changes:
- added takeover of caption and message for $host.UI.PromptForCredential and Get-Credential.
List of changes (line numbers are from PS2EXE-GUI v0.5.0.8):
line 8 - adjusted version number
line 21 - adjusted version number
lines 389 to 392 - removed comments
line 437 - added Unicode coding
line 458 - changed comment
line 461 - inserted message and caption takeover
line 474 - changed comment
line 1905 - adjusted version number
PS2EXE-GUI v0.5.0.8
Changes:
- $ERRORACTIONPREFERENCE = 'Stop' bug corrected. The last error is not swallowed anymore.
List of changes (line numbers are from PS2EXE-GUI v0.5.0.7):
line 8 - adjusted version number
line 21 - adjusted version number
line 1905 - adjusted version number
line 2167 - inserted expression to retrieve last error
PS2EXE-GUI v0.5.0.7
Changes:
- parameter parsing bug corrected. A slash is not accepted as an introducing character for named parameters anymore.
List of changes (line numbers are from PS2EXE-GUI v0.5.0.6):
line 8 - adjusted version number
line 21 - adjusted version number
line 1905 - adjusted version number
line 2102 - corrected regular expression for parameter parsing
PS2EXE-GUI v0.5.0.6
Changes:
- button texts for input corrected, tries now to use localized strings for OK and Cancel
List of changes (line numbers are from PS2EXE-GUI v0.5.0.5):
line 8 - adjusted version number
line 21 - adjusted version number
lines 906 to 959 - get localized strings for OK and Cancel in input bix
lines 975 to 986 - translated some comments
line 1809 - adjusted version number
PS2EXE-GUI v0.5.0.5
Changes:
- new parameters -title, -description, -company, -product, -copyright, -trademark and -version to set meta data (as can be seen in the properties dialog in tab "Details" in Windows Explorer)
- new parameter -requireAdmin generates an executable that requires administrative rights and forces the UAC dialog (if UAC is enabled)
- new parameter -virtualize generates an executable that uses application virtualization when accessing protected system file system folders or registry
- several minor fixes
List of changes (line numbers are from PS2EXE-GUI v0.5.0.4):
line 1 - introduced new parameters, spread parameters over 4 lines for better readability
line 5 - adjusted version number
line 18 - adjusted version number
line 26 - shortened expression
line 32 - shortened expression
lines 54 to 60 - help text for new parameters
line 119 - inserted check that -requireAdmin and -virtualize are not provided together
line 152 - inserted new parameters for powershell v2
lines 153 to 155 - prevent call to powershell v2 ps2exe when psexe is compiled itself
line 168 - shortened expression
line 174 - shortened expression
line 180 - inserted value checks for new parameters
lines 251 to 252 - inserted compiler options for new parameters
line 303 - inserted compiler directives for new parameters
line 1809 - adjusted version number
line 2006 to 2036 - corrected bug in parameter computation ("number in parameter name")
line 2054 - translated comment
lines 2107 to 2110 - removed comments
lines 2146 to 2151 - corrected encoding for write of config file
line 2161 - appended deletion of manifest file (if generated before)
PS2EXE-GUI v0.5.0.4
Changes:
- corrected input handler: advanced parameters ([CmdletBinding()]) are working for compiled scripts now
- implemented input pipeline (only of strings) for compiled scripts (only Powershell V3 and above), e.g, Get-ChildItem | CompiledScript.exe
- Powershell V2 (or PS2EXE with switch -runtime20) compiles with .Net V3.5x compiler rather than with .Net V2.0 compiler now (there is no Microsoft support for .Net V2 anymore, so I won't do either)
- implemented missing console screen functions to move, get and set screen blocks (see example ScreenBuffer.ps1)
- several minor fixes
List of changes (line numbers are from PS2EXE-GUI v0.5.0.3):
line 5 - adjusted version number
line 18 - adjusted version number
lines 186 to 193 - check for V3.5 compiler, warning if only V2 compiler found
line 407 - inserted pinvoke definitions for new screen functions
lines 519 to 522 - implemented GetBufferContents method
lines 588 to 591 - implemented ScrollBufferContents method
line 598 - correction of block size in SetBufferContents(Rectangle, BufferCell) method
lines 606 to 609 - implemented SetBufferContents(Coordinats, BufferCell[,]) method
lines 1157 to 1160 - exception displays actual error message instead of fixed text
lines 1226 to 1229 - exception displays actual error message instead of fixed text
line 1664 - adjusted version number
line 1701 - inserted pinvoke definitions for string pipeline functions
lines 1765 to 1769 - corrected input handler and inserted input string pipeline
lines 1771 to 1774 - better variable name for output collection
line 1876 - corrected parameter
line 1878 - modifications for input string pipeline
PS2EXE-GUI v0.5.0.3
Changes:
- Write-Progress implemented for GUI output (parameter -noConsole), nesting of progresses is ignored
- removed unnecessary parameter -runtime30 (there is no such thing as a 3.x runtime)
- if -runtime20 and -runtime40 is supplied together an error message is generated now
- two references to Console removed from -noConsole mode for better stability
List of changes (line numbers are from PS2EXE-GUI v0.5.0.2):
line 1 - removed parameter -runtime30
line 5 - adjusted version number
line 18 - adjusted version number
lines 26 to 28 - check for runtime40 instead of runtime30
lines 38 to 66 - overworked help text
lines 121 to 135 - removed runtime30
lines 163 to 175 - removed runtime30
line 205 - reference to ConsoleHost only in console mode now
lines 208 to 213 - removed runtime30
lines 217 to 233 - removed runtime30
line 254 - removed unnecessary comment
line 956 - inserted new class ProgressForm for display of a progress bar in GUI mode
line 1421 - inserted new variable for WriteProgess in GUI mode
lines 1422 to 1425 - method WriteProgress implemented for GUI mode
line 1519 - adjusted version number
lines 1641 to 1645 - replaced Console.WriteLine with MessageBox.Show for GUI mode
line 1768 - corrected typo
lines 1817 to 1821 - removed runtime30
PS2EXE-GUI v0.5.0.2
Changes:
- STA or MTA mode is used corresponding to the powershell version when not specified (V3 or higher: STA, V2: MTA)
This prevents problems with COM and some graphic dialogs
- icon file is seeked in the correct directory
List of changes (line numbers are from PS2EXE-GUI v0.5.0.1):
line 5 - adjusted version number
line 18 - adjusted version number
lines 111 to 115 - overworked routine to get icon file path
line 174 - when no -STA or -MTA switch is given, the threading apartment is set here according to the powershell version
PS2EXE-GUI v0.5.0.1
Changes:
- PROGRESS handler removed
List of changes (line numbers are from PS2EXE-GUI v0.5.0.0):
line 5 - adjusted version number
line 18 - adjusted version number
lines 1600 to 1603 - removed handler for progress stream, resulted in progress output converted to string (e.g.: "parent = -1 id = 0 act = Activity stat = State cur = pct = -1 sec = -1 type = Completed")
PS2EXE-GUI v0.5.0.0
Changes by Markus Scholtes:
- treats Powershell 5 or above like Powershell 4
- Unused classes ReadKeyForm and CredentialForm in console output removed
- remove dead code
- System.Windows.Forms and System.Drawing are loaded for GUI output
- Write methods use MessageBox.Show in GUI output
- InputBox class introduced which is used for Readline, Read LineasSecureString and Prompt with GUI output
- ChoiceBox-Klasse introduced which is used for PromptForChoice with GUI output
- ReadKeyBox-Klasse introduced which is used for ReadKey with GUI output
- Prompt accepts SecureString and PSCredential as field types now
- Prompt: when conversion of input fails, the prompt reappears
- PromptForPassword: corrected string overflow in 32 bit runtime
- PromptForCredential for console: computer name is used, user name is demanded when needed
- PromptForChoice accepts help texts and default values now
- the console output methods do not use black background and white foreground, but use the actual colors now
- missing methods WriteLine() and WriteLine(ConsoleColor, ConsoleColor, String) added
- method SetBufferContents for Clear-Host added
- method KeyAvailable added
- method BufferSize for GUI output corrected
- in GUI output the class Console is not called anymore
- input and output file are seeked and generated in the correct directory
- check that input file is not the same as the output file
- doubled VERBOSE and WARNING handler removed
- new, corrected and much expanded parser for command line parameters
- several small fixes
- revision of help and error texts
What is still missing:
Write-Progress
List of changes (line numbers are from PS2EXE v0.5.0.0):
lines 38 to 70 - updated help text
line 74 - powershell versions greater than 4 are treated like version 4
lines 94 to 107 - corrected generation of absolute file paths
line 108 - added check whether input file is the same as output file
line 140 - added icon file parameter for runtime 2.0
line 167 - omitted, no need for Set-Location
lines 207 to 208 - omitted, full paths already retrieved
lines 253 to 272 - omitted
lines 280 to 342 - omitted
line 414 - corrected StringBuilder constructor for 32 bit environments
line 430 - allocated enough space for long user or domain names
lines 447 to 561 - omitted
lines 564 to 582 - moved to beginning of c# code
line 579 - added Forms and Drawing namespaces in GUI mode
line 586 - removed variable CONSOLE, added variables to store console colors for GUI environment
lines 588 to 598 - added GUI support for BackgroundColor
lines 600 to 614 - corrected dummy size for BufferSize for GUI, so WriteLine is called
lines 616 to 627 - added GUI support for CursorPosition
lines 629 to 639 - added GUI support for CursorSize
line 643 - removed exception
lines 646 to 656 - added GUI support for ForegroundColor
lines 663 to 669 - implemented KeyAvailable
lines 671 to 674 - added GUI support for MaxPhysicalWindowSize
lines 676 to 679 - added GUI support for MaxWindowSize
line 694 - added support for NUMLOCK
lines 698 to 700 - added working GUI support for ReadKey
lines 709 to 712 - implemented, even Clear-Host works now
lines 719 to 733 - added GUI support for WindowPosition
lines 735 to 749 - added GUI support for WindowSize
lines 751 to 761 - added GUI support for WindowTitle
line 762 - added classes for input boxes, choice boxes and read key boxes
line 765 - removed constant CONSOLE
line 772 - initializing of screen colors added
lines 775 to 856 - Prompt: added GUI support, added secure text, added help messages
lines 858 to 906 - PromptForChoice: added GUI support
lines 908 to 937 - PromptForCredential: corrected handling of readonly user names
lines 939 to 964 - PromptForCredential: corrected handling of readonly user names
line 973 - added private variables for input boxes
lines 974 to 977 - added GUI support for ReadLine
lines 979 to 986 - ReadLineAsSecureString: implemented password input in console and GUI
lines 988 to 993 - Write: corrected color management, added GUI support
lines 995 to 1000 - Write: corrected color management, added GUI support
lines 1002 to 1007 - WriteDebugLine: corrected color management, added GUI support
lines 1009 to 1014 - WriteErrorLine: corrected color management, added GUI support
line 1016 - added function WriteLine(ConsoleColor, ConsoleColor, string)
line 1016 - added function WriteLine()
lines 1016 to 1021 - WriteLine: removed color management, added GUI support
lines 1028 to 1033 - WriteVerboseLine: corrected color management, added GUI support
lines 1035 to 1040 - WriteWarningLine: corrected color management, added GUI support
line 1047 - removed constant CONSOLE
line 1110 - set correct version number
line 1150 - removed constant CONSOLE
line 1193 to 1206 - removed Console.CancelKeyPress in case there is no console
line 1213 to 1216 - removed handler for verbose stream, resulted in double verbose output
line 1217 to 1220 - removed handler for warning stream, resulted in double warning output
line 1275 to 1280 - inserted a much improved routine to retrieve parameters (still faulty in some situations)
lines 1299 to 1303 - exception is displayed in a message box when there is no console
lines 1305 to 1309 - wait text is displayed in a message box when there is no console

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,14 @@
# Example script to retrieve path to script
# When compiled with PS2EXE the variable MyCommand contains no path anymore
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript")
{ # Powershell script
$ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
}
else
{ # PS2EXE compiled script
$ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0])
}
"Directory of executable file: " + $ScriptPath

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,23 @@
# Example script to process pipeline
# Type of pipeline object gets lost for compiled scripts, pipeline objects are always strings
[CmdletBinding()]
Param(
[parameter(Mandatory=$FALSE, ValueFromPipeline=$TRUE)] [AllowEmptyString()]$Pipeline
)
BEGIN
{
"Reading pipeline as array of strings"
$COUNTER = 0
}
PROCESS
{
if ($Pipeline -eq $NULL)
{ Write-Output "No element found in the pipeline" }
else
{
$COUNTER++
Write-Output "$COUNTER`: $Pipeline"
}
}

View File

@@ -0,0 +1,13 @@
# demo program for Write-Progress
1..10 | % { Write-Progress -Activity "Activity $_" -Status "State $_" -Id 1 -CurrentOperation "Operation $_" -PercentComplete ([int]10*$_) -SecondsRemaining (10-$_) ;
Start-Sleep 1 }
Start-Sleep 3
Write-Progress -Activity "Activity" -Status "State" -Id 1 -Completed
Write-Host "Completed"
Start-Sleep 1
Write-Progress -Activity "New progress" -Status "New state" -PercentComplete 33 -SecondsRemaining 734
Start-Sleep 3
Write-Output "Exiting program"

View File

@@ -0,0 +1,10 @@
"ReadKey-Demo`n`nWait for KeyDown event first, then for KeyUp-Event`n(only in KeyUp event modification keys are visible)"
$Host.UI.RawUI.ReadKey("IncludeKeyDown,NoEcho")
Read-Host "`nAfter pressing Enter there will a pause of two seconds before waing for the KeyUp event"
sleep 2
$Host.UI.RawUI.ReadKey("IncludeKeyUp")
if ($Host.UI.RawUI.KeyAvailable) { "Key in key buffer found" } else { "No key in key buffer found" }

View File

@@ -0,0 +1,85 @@
# Example script for screen operations
function Get-CharFromConsolePosition([int]$X, [int]$Y)
{ # function to get the character of a position in the console buffer
$RECT = New-Object System.Management.Automation.Host.Rectangle $X, $Y, $X, $Y
$host.UI.RawUI.GetBufferContents($RECT)[0,0]
}
# fill block with a character
$BufferCell = New-Object System.Management.Automation.Host.BufferCell "O", "White", "Red", "Complete"
# Complete - The character occupies one BufferCell structure.
# Leading - The character occupies two BufferCell structures, with this cell being the leading cell (UNICODE)
# Trailing - The character occupies two BufferCell structures, with this cell being the trailing cell (UNICODE)
$Source = New-Object System.Management.Automation.Host.Rectangle 10, 10, 29, 29
$host.UI.RawUI.SetBufferContents($Source, $BufferCell)
# read block into buffer
$ScreenBuffer = New-Object -TypeName 'System.Management.Automation.Host.BufferCell[,]' -ArgumentList ($Source.Bottom - $Source.Top + 1),($Source.Right - $Source.Left + 1)
$ScreenBuffer = $host.UI.RawUI.GetBufferContents($Source)
# modify block in buffer
$MAXDIMENSION = [Math]::Min(($Source.Bottom - $Source.Top + 1),($Source.Right - $Source.Left + 1))
for ($COUNTER = 0; $COUNTER -lt $MAXDIMENSION; $COUNTER++)
{
$ScreenBuffer[$COUNTER,$COUNTER] = New-Object System.Management.Automation.Host.BufferCell "X", "White", "Red", "Complete"
$ScreenBuffer[($MAXDIMENSION - $COUNTER - 1),$COUNTER] = New-Object System.Management.Automation.Host.BufferCell "X", "White", "Red", "Complete"
}
# write back buffer to screen
$host.UI.RawUI.SetBufferContents((New-Object System.Management.Automation.Host.Coordinates $Source.Left, $Source.Top), $ScreenBuffer)
# move block
# define fill character for source range
$BufferCell.Character = "-"
$BufferCell.ForegroundColor = $host.UI.RawUI.ForegroundColor
$BufferCell.BackgroundColor = $host.UI.RawUI.BackgroundColor
# define clipping area (a ten character wide border)
$Clip = New-Object System.Management.Automation.Host.Rectangle 10, 10, ($host.UI.RawUI.WindowSize.Width - 10), ($host.UI.RawUI.WindowSize.Height - 10)
# repeat ten times
for ($i = 1; $i -le 10; $i++)
{
for ($X = $Source.Left + 1; $X -le ($host.UI.RawUI.WindowSize.Width - $Source.Right + $Source.Left); $X++)
{
$Destination = New-Object System.Management.Automation.Host.Coordinates $X, 10
$host.UI.RawUI.ScrollBufferContents($Source, $Destination, $Clip, $BufferCell)
$Source.Right++
$Source.Left++
}
for ($Y = $Source.Top + 1; $Y -le ($host.UI.RawUI.WindowSize.Height - $Source.Bottom + $Source.Top); $Y++)
{
$Destination = New-Object System.Management.Automation.Host.Coordinates $Source.Left, $Y
$host.UI.RawUI.ScrollBufferContents($Source, $Destination, $Clip, $BufferCell)
$Source.Bottom++
$Source.Top++
}
for ($X = $Source.Left - 1; $X -ge 10; $X--)
{
$Destination = New-Object System.Management.Automation.Host.Coordinates $X, $Source.Top
$host.UI.RawUI.ScrollBufferContents($Source, $Destination, $Clip, $BufferCell)
$Source.Right--
$Source.Left--
}
for ($Y = $Source.Top - 1; $Y -ge 10; $Y--)
{
$Destination = New-Object System.Management.Automation.Host.Coordinates $Source.Left, $Y
$host.UI.RawUI.ScrollBufferContents($Source, $Destination, $Clip, $BufferCell)
$Source.Bottom--
$Source.Top--
}
}
# get character from screen
"Character at position (10/10): "
Get-CharFromConsolePosition 10 10

Binary file not shown.

View File

@@ -0,0 +1,37 @@
MICROSOFT LIMITED PUBLIC LICENSE version 1.1
This license governs use of code marked as <20>sample<6C> or <20>example<6C> available on this web site without a license agreement, as provided under the section above titled <20>NOTICE SPECIFIC TO SOFTWARE AVAILABLE ON THIS WEB SITE.<2E> If you use such code (the <20>software<72>), you accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms <20>reproduce,<2C> <20>reproduction,<2C> <20>derivative works,<2C> and <20>distribution<6F> have the same meaning here as under U.S. copyright law.
A <20>contribution<6F> is the original software, or any additions or changes to the software.
A <20>contributor<6F> is any person that distributes its contribution under this license.
<EFBFBD>Licensed patents<74> are a contributor<6F>s patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant - Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant - Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors<72> name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(E) The software is licensed <20>as-is.<2E> You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
(F) Platform Limitation - The licenses granted in sections 2(A) and 2(B) extend only to the software or derivative works that you create that run directly on a Microsoft Windows operating system product, Microsoft run-time technology (such as the .NET Framework or Silverlight), or Microsoft application platform (such as Microsoft Office or Microsoft Dynamics).

View File

@@ -0,0 +1,22 @@
Microsoft Public License (Ms-PL)
from http://www.microsoft.com/opensource/licenses.mspx#Ms-PL
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. A "contribution" is the original software, or any additions or changes to the software. A "contributor" is any person that distributes its contribution under this license. "Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,14 @@
@ECHO OFF
set cmd=
:Loop
IF "%~1"=="" GOTO Continue
set cmd=%cmd% '%1'
SHIFT
GOTO Loop
:Continue
rem echo %cmd%
powershell.exe -command "&'.\ps2exe.ps1' %cmd%"

View File

@@ -0,0 +1,15 @@
call "callPS2EXE.bat" "test.ps1" "test.exe" -iconFile PS2EXE.ico
call "callPS2EXE.bat" "test.ps1" "test_x64.exe" -x64
call "callPS2EXE.bat" "test.ps1" "test_x86.exe" -x86
call "callPS2EXE.bat" "test.ps1" "test_20_STA.exe" -sta -runtime20 -iconFile PS2EXE.ico
call "callPS2EXE.bat" "test.ps1" "test_30_MTA.exe" -mta -runtime30
call "callPS2EXE.bat" "test.ps1" "test_30_NOCONSOLE.exe" -noconsole -runtime30
call "callPS2EXE.bat" "test.ps1" "test_20_NOCONSOLE.exe" -noconsole -runtime20
call "callPS2EXE.bat" "test.ps1" "test_40.exe" -runtime40

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,81 @@
PS2EXE-GUI v0.5.0.18
Release: 2019-12-16
Overworking of the great script of Igor Karstein with GUI support by Markus Scholtes.
The GUI output and input is activated with one switch, real windows executables
are generated.
https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5
All of you know the fabulous script PS2EXE by Ingo Karstein you can download here: PS2EXE : "Convert" PowerShell Scripts to EXE Files.
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).
Module based version available now on Powershell Gallery, see here (https://www.powershellgallery.com/packages/ps2exe) or install with Install-Module PS2EXE
Project page on github is here: https://github.com/MScholtes/PS2EXE.
Update v0.5.0.18 - 2019-12-16
Fixed "unlimited window width for GUI windows" issue in ps2exe.ps1 and Win-PS2EXE
Full list of changes and fixes in Changes.txt.
Includes Win-PS2EXE, a small graphical front end for PS2EXE.
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
GUI support:
- 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
- no console windows appears, real windows executables are generated
- just compile with switch "-noConsole" for this feature (i.e. .\ps2exe.ps1 .\output.ps1 -noConsole)
- see remarks below for formatting of output in GUI mode
Compile all of the examples in the Examples sub directory with
BuildExamples.bat
Every script will be compiled to a console and a GUI version (-NoConsole).
Remarks:
GUI mode output formatting:
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).
Config files:
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.
Password security:
Never store passwords in your compiled script! One can simply decompile the script with the parameter -extract. For example
Output.exe -extract:C:\Output.ps1
will decompile the script stored in Output.exe.
Script variables:
Since PS2EXE converts a script to an executable, script related variables are not available anymore. Especially the variable $PSScriptRoot is empty.
The variable $MyInvocation is set to other values than in a script.
You can retrieve the script/executable path independant of compiled/not compiled with the following code (thanks to JacquesFS):
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript")
{ $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition }
else
{ $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) }
Window in background in -noConsole mode:
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.
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.
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).
The following example will not open a window in the background anymore as a single call of "ipconfig | Out-String" will do:
$Host.UI.RawUI.FlushInputBuffer()
ipconfig | Out-String
$Host.UI.RawUI.FlushInputBuffer()

View File

@@ -0,0 +1,57 @@
PS2EXE
Script to convert powershell scripts to standalone executables
Assuming "ps2exe.ps1" and a scoure script "source.ps1" are in the current directory,
.\ps2exe.ps1 .\source.ps1 .\target.exe
compiles "source.ps1" into the executable target.exe
(if ".\target.exe" is omitted, output is written to ".\source.exe").
or start Win-PS2EXE for a graphical front end!
Usage:
ps2exe.ps1 [-inputFile] '<file_name>' [[-outputFile] '<file_name>'] [-verbose]
[-debug] [-runtime20|-runtime40] [-lcid <id>] [-x86|-x64] [-STA|-MTA] [-noConsole]
[-credentialGUI] [-iconFile '<filename>'] [-title '<title>'] [-description '<description>']
[-company '<company>'] [-product '<product>'] [-copyright '<copyright>'] [-trademark '<trademark>']
[-version '<version>'] [-configFile] [-noOutput] [-noError] [-requireAdmin] [-supportOS]
[-virtualize] [-longPaths]
inputFile = Powershell script that you want to convert to executable
outputFile = destination executable file name, defaults to inputFile with extension '.exe'
runtime20 = this switch forces PS2EXE to create a config file for the generated executable that contains the
"supported .NET Framework versions" setting for .NET Framework 2.0/3.x for PowerShell 2.0
runtime40 = this switch forces PS2EXE to create a config file for the generated executable that contains the
"supported .NET Framework versions" setting for .NET Framework 4.x for PowerShell 3.0 or higher
lcid = location ID for the compiled executable. Current user culture if not specified
x86 or x64 = compile for 32-bit or 64-bit runtime only
STA or MTA = 'Single Thread Apartment' or 'Multi Thread Apartment' mode
noConsole = the resulting executable will be a Windows Forms app without a console window
credentialGUI = use GUI for prompting credentials in console mode
iconFile = icon file name for the compiled executable
title = title information (displayed in details tab of Windows Explorer's properties dialog)
description = description information (not displayed, but embedded in executable)
company = company information (not displayed, but embedded in executable)
product = product information (displayed in details tab of Windows Explorer's properties dialog)
copyright = copyright information (displayed in details tab of Windows Explorer's properties dialog)
trademark = trademark information (displayed in details tab of Windows Explorer's properties dialog)
version = version information (displayed in details tab of Windows Explorer's properties dialog)
configFile = write config file (<outputfile>.exe.config)
noOutput = the resulting executable will generate no standard output (includes verbose and information channel)
noError = the resulting executable will generate no error output (includes warning and debug channel)
requireAdmin = if UAC is enabled, compiled executable run only in elevated context (UAC dialog appears if required)
supportOS = use functions of newest Windows versions (execute [Environment]::OSVersion to see the difference)
virtualize = application virtualization is activated (forcing x86 runtime)
longPaths = enable long paths ( > 260 characters) if enabled on OS (works only with Windows 10)
A generated executables has the following reserved parameters:
-debug Forces the executable to be debugged. It calls "System.Diagnostics.Debugger.Break()".
-extract:<FILENAME> Extracts the powerShell script inside the executable and saves it as FILENAME.
The script will not be executed.
-wait At the end of the script execution it writes "Hit any key to exit..." and waits for a key to be pressed.
-end All following options will be passed to the script inside the executable.
All preceding options are used by the executable itself and will not be passed to the script.

Binary file not shown.

BIN
Tools/PS2EXE-GUI/ps2exe.ps1 Normal file

Binary file not shown.