Last active
July 20, 2020 04:43
-
-
Save matthewjberger/be86c0f6370f3574b2a5c94890a24086 to your computer and use it in GitHub Desktop.
A GUI in Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.\ps2exe.ps1 ..\form.ps1 -outputFile output.exe -requireAdmin -noConfigFile -noConsole -noError -nooutput -x64 -runtime40 | |
from | |
https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Self-Elevate | |
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { | |
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { | |
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments | |
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine | |
Exit | |
} | |
} | |
# Create the form | |
Add-Type -AssemblyName System.Windows.Forms | |
[System.Windows.Forms.Application]::EnableVisualStyles() | |
$PSControlForm = New-Object system.Windows.Forms.Form | |
$PSControlForm.ClientSize = '180,298' | |
$PSControlForm.text = "My Form" | |
$PSControlForm.TopMost = $false | |
$FirstButton = New-Object system.Windows.Forms.Button | |
$FirstButton.text = "First thing" | |
$FirstButton.width = 89 | |
$FirstButton.height = 30 | |
$FirstButton.location = New-Object System.Drawing.Point(44,33) | |
$FirstButton.Font = 'Microsoft Sans Serif,10' | |
$SecondButton = New-Object system.Windows.Forms.Button | |
$SecondButton.text = "Second thing" | |
$SecondButton.width = 89 | |
$SecondButton.height = 30 | |
$SecondButton.location = New-Object System.Drawing.Point(44,101) | |
$SecondButton.Font = 'Microsoft Sans Serif,10' | |
$ThirdButton = New-Object system.Windows.Forms.Button | |
$ThirdButton.text = "Third thing" | |
$ThirdButton.width = 89 | |
$ThirdButton.height = 30 | |
$ThirdButton.location = New-Object System.Drawing.Point(44,171) | |
$ThirdButton.Font = 'Microsoft Sans Serif,10' | |
$FourthButton = New-Object system.Windows.Forms.Button | |
$FourthButton.text = "Fourth thing" | |
$FourthButton.width = 89 | |
$FourthButton.height = 30 | |
$FourthButton.location = New-Object System.Drawing.Point(44,240) | |
$FourthButton.Font = 'Microsoft Sans Serif,10' | |
$PSControlForm.controls.AddRange(@($FirstButton,$SecondButton,$ThirdButton,$FourthButton)) | |
function RunInBackground() { Start-Process @args } | |
function FirstButtonClicked { | |
RunInBackground ./script.bat | |
} | |
function SecondButtonClicked { | |
RunInBackground ./script2.bat | |
} | |
function ThirdButtonClicked { | |
RunInBackground ./script3.bat | |
} | |
function FourthButtonClicked { | |
RunInBackground ./script4.bat | |
} | |
$FirstButton.Add_MouseClick({ FirstButtonClicked }) | |
$SecondButton.Add_MouseClick({ SecondButtonClicked }) | |
$ThirdButton.Add_MouseClick({ ThirdButtonClicked }) | |
$FourthButton.Add_MouseClick({ FourthButtonClicked }) | |
$PSControlForm.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment