Created
February 12, 2016 14:45
-
-
Save lazywinadmin/ff8717a1c1b393305ff8 to your computer and use it in GitHub Desktop.
Send the output to Notepad
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
#requires -Version 2 | |
#http://powershell.com/cs/blogs/tips/archive/2016/02/11/send-text-to-notepad.aspx | |
function Out-Notepad | |
{ | |
param | |
( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
[String] | |
[AllowEmptyString()] | |
$Text | |
) | |
begin | |
{ | |
$sb = New-Object System.Text.StringBuilder | |
} | |
process | |
{ | |
$null = $sb.AppendLine($Text) | |
} | |
end | |
{ | |
$text = $sb.ToString() | |
$process = Start-Process notepad -PassThru | |
$null = $process.WaitForInputIdle() | |
$sig = ' | |
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); | |
[DllImport("User32.dll")]public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam); | |
' | |
$type = Add-Type -MemberDefinition $sig -Name APISendMessage -PassThru | |
$hwnd = $process.MainWindowHandle | |
[IntPtr]$child = $type::FindWindowEx($hwnd, [IntPtr]::Zero, "Edit", $null) | |
$null = $type::SendMessage($child, 0x000C, 0, $text) | |
} | |
} | |
#Get-Content $env:windir\system32\drivers\etc\hosts | Out-Notepad | |
#Get-Process | Out-String | Out-Notepad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment