I'm building a process (so far I've tried VBA, Python and C# on .Net Framework 4.7.2) which requires to put some string to clipboard on Windows 10 machine behind the lock screen. For testing I've reduced it to only two commands (pseudo code, since 3 languages used. Details in the end of the question):
SleepForFiveSec(); //to provide time for locking screen
// now locking machine
SetClipboardContent();
Clipboard is responsive on unlocked session, but becomes unavailable and returns "clipboard locked" error (language specific), when machine is locked.
I've tested several clipboard related techniques found in google/stackoverflow for mentioned languages (about 6 in total) and none works so far.
Machine is running on Windows 10 Enterprise (tested on 3 different machines with the same version).
Code examples:
C# opt 1:
using System.Windows.Forms;
.....
[STAThread]
static void Main()
{
System.Threading.Thread.Sleep(5000);
Clipboard.SetText("test copy clip");
}
C# opt 2 (for check what is locking clipboard):
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr GetOpenClipboardWindow();
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int GetWindowText(int hwnd, StringBuilder text, int count);
private static string getOpenClipboardWindowText()
{
IntPtr hwnd = GetOpenClipboardWindow();
StringBuilder sb = new StringBuilder(501);
GetWindowText(hwnd.ToInt32(), sb, 500);
return sb.ToString();
}
python opt.1:
import pyperclip
import time
time.sleep(5)
pyperclip.copy('text')
python opt.2:
import win32clipboard
import time
time.sleep(5)
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText('text')
win32clipboard.CloseClipboard()
VBA opt.1:
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText "text for input"
clipboard.PutInClipboard
VBA opt.2: Text To Clipboard in VBA Windows 10 Issue