Example usage:
.\make-shortcut.ps1 `
-Command "powershell.exe -ExecutionPolicy Bypass .\Scripts\start-windowsterminal.ps1" `
-IconFile 'E:\icons\WindowsTerminal_101.ico' `
-Output 'E:\Windows Terminal.exe'| param( | |
| [Parameter(Mandatory)] [string] $Command, | |
| [Parameter(Mandatory)] [string] $IconFile, | |
| [string] $Output, | |
| [switch] $Keep | |
| ) | |
| (Get-Content -Encoding UTF8 template.c) -replace "COMMAND_PLACEHOLDER", ($Command -replace '\\', '\\') | Out-File -Encoding UTF8 temp.c | |
| "icon ICON `"$($IconFile -replace '\\', '\\')`"" | Out-File -Encoding UTF8 temp.rc | |
| # Make sure MinGW is installed and can be found in PATH | |
| windres.exe temp.rc temp.o | |
| $gccCmd = "gcc.exe temp.c temp.o -mwindows" | |
| if ($Output) { | |
| $gccCmd += " -o `"$Output`"" | |
| } | |
| else { | |
| $gccCmd += " -o out.exe" | |
| } | |
| Invoke-Expression $gccCmd | |
| if (-not $Keep) { | |
| Remove-Item temp.c, temp.rc, temp.o | |
| } |
| #include <windows.h> | |
| int main() | |
| { | |
| WinExec("COMMAND_PLACEHOLDER", SW_HIDE); | |
| return 0; | |
| } |