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 33 34 35 |
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) # EmptyClipboard: Empties the clipboard and frees handles to data in the clipboard. The function then assigns ownership of the clipboard to the window that currently has the clipboard open. [NS.Clipboard]::EmptyClipboard() $ansiTextFormat = 1 # StringToHGlobalAnsi: Copia el contenido de un String administrado en la memoria no administrada, convirtiéndolo en formato ANSI mientras realiza la copia. $ptr = [Runtime.InteropServices.Marshal]::StringToHGlobalAnsi("copiar en portapapeles") # SetClipboardData: Places data on the clipboard in a specified clipboard format. The window must be the current clipboard owner, and the application must have called the OpenClipboard function. [NS.Clipboard]::SetClipboardData($ansiTextFormat,$ptr) # 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 |