Skip to content

Instantly share code, notes, and snippets.

@bsdayo
Last active May 21, 2024 01:23
Show Gist options
  • Select an option

  • Save bsdayo/3b958c44028309906c4aa1fd90377b50 to your computer and use it in GitHub Desktop.

Select an option

Save bsdayo/3b958c44028309906c4aa1fd90377b50 to your computer and use it in GitHub Desktop.
Super "Windows shortcut" maker with embedded icon
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;
}

Super "Windows shortcut" maker with embedded icon

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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment