Skip to content

Instantly share code, notes, and snippets.

@citelao
Last active April 15, 2025 15:53
Show Gist options
  • Save citelao/f6b27a264ba6d767e044da8b89972dbf to your computer and use it in GitHub Desktop.
Save citelao/f6b27a264ba6d767e044da8b89972dbf to your computer and use it in GitHub Desktop.
Show a message box in PS1
$script = @"
using System;
using System.Runtime.InteropServices;
public partial class MessageBoxer
{
// Import user32.dll (containing the function we need) and define
// the method corresponding to the native function.
[DllImport(`"user32.dll`", SetLastError = true)]
private static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType);
public static void ShowBox()
{
// Invoke the function as a regular managed method.
MessageBox(IntPtr.Zero, `"Command-line message box`", `"Attention!`", 0);
}
}
"@;
# Compile the C# code locally
Add-Type -TypeDefinition $script -Language CSharp
$args = @()
[MessageBoxer]::ShowBox()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment