Last active
April 15, 2025 15:53
-
-
Save citelao/f6b27a264ba6d767e044da8b89972dbf to your computer and use it in GitHub Desktop.
Show a message box in PS1
This file contains hidden or 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
$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