1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Add-Type -Namespace NS -Name Clipboard -MemberDefinition @" [DllImport("user32.dll", SetLastError=true)] public static extern bool EmptyClipboard(); [DllImport("user32.dll", SetLastError=true)] public static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem); [DllImport("user32.dll", SetLastError=true)] public static extern IntPtr GetClipboardData(uint uFormat); [DllImport("user32.dll", SetLastError=true)] public static extern bool OpenClipboard(IntPtr hWndNewOwner); [DllImport("user32.dll", SetLastError=true)] public static extern bool CloseClipboard(); [DllImport("user32.dll", SetLastError=true)] public static extern uint EnumClipboardFormats(uint format); "@ # OpenClipboard: Opens the clipboard for examination and prevents other applications from modifying the clipboard content. [NS.Clipboard]::OpenClipboard([IntPtr]::Zero) | Out-Null # EnumClipboardFormats: Enumerates the data formats currently available on the clipboard. [NS.Clipboard]::EnumClipboardFormats(0) $ansiTextFormat = 1 # GetClipboardData: Retrieves data from the clipboard in a specified format. The clipboard must have been opened previously. $ptr = [NS.Clipboard]::GetClipboardData($ansiTextFormat) # PtrToStringAnsi: Asigna un String administrado y copia en él total o parcialmente una cadena ANSI (en Windows) o UTF-8 (en Unix) no administrada. [Runtime.InteropServices.Marshal]::PtrToStringAnsi($ptr) # CloseClipboard: Closes the clipboard. [NS.Clipboard]::CloseClipboard() | Out-Null "hola" |