using LoginPI.Engine.ScriptBase; using System; using System.Runtime.InteropServices; public class getSetClipboardText : ScriptBase { private void Execute() { /* -Disclaimer: This workload is provided as-is and might need further configuration and customization to work successfully in each unique environment. For further Professional Services-based customization please consult with the Login VSI Support and Services team. Please refer to the Help Center section "Application Customization" for further self-help information regarding workload crafting and implementation. -Run the workload against the "target" using Script Editor to ensure it will work before uploading it and testing with it -If needed, configure the Set global variables section of this workload -Go through the workload to understand what it's doing. Comment out any unneeded app tests (code blocks) or add on any needed functional testing -This workload will: retrieve or set the current clipboard text -Workload version and changelist: --V1.0 | original -Leave Application running compatibility: false */ //Output current clipboard text to log Log(GetClipboard()); //Set clipboard text SetClipboard("testing 123"); //Output current clipboard text to log Log(GetClipboard()); } [DllImport("user32.dll")] static extern IntPtr GetClipboardData(uint uFormat); [DllImport("user32.dll")] static extern bool IsClipboardFormatAvailable(uint format); [DllImport("user32.dll", SetLastError = true)] static extern bool OpenClipboard(IntPtr hWndNewOwner); [DllImport("user32.dll", SetLastError = true)] static extern bool CloseClipboard(); [DllImport("kernel32.dll")] static extern IntPtr GlobalLock(IntPtr hMem); [DllImport("kernel32.dll")] static extern bool GlobalUnlock(IntPtr hMem); [DllImport("user32.dll", SetLastError = true)] static extern IntPtr SetClipboardData(uint uFormat, IntPtr data); [DllImport("user32.dll")] static extern bool EmptyClipboard(); const uint CF_UNICODETEXT = 13; static string GetClipboard() { if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) return ""; if (!OpenClipboard(IntPtr.Zero)) return ""; string data = ""; var hGlobal = GetClipboardData(CF_UNICODETEXT); if (hGlobal != IntPtr.Zero) { var lpwcstr = GlobalLock(hGlobal); if (lpwcstr != IntPtr.Zero) { data = Marshal.PtrToStringUni(lpwcstr); GlobalUnlock(lpwcstr); } } CloseClipboard(); return data; } static void SetClipboard(string text) { OpenClipboard(IntPtr.Zero); var ptr = Marshal.StringToHGlobalUni(text); SetClipboardData(13, ptr); CloseClipboard(); } }