我正在构建一个进程(到目前为止,我已经在WindowsFramework4.7.2上尝试过VBA、Python和C# ),它需要在锁定屏幕后面的Windows10机器上将一些字符串放到剪贴板中。为了测试,我已经将它减少到只有两个命令(伪代码,因为使用了三种语言。问题末尾的详情):
SleepForFiveSec(); //to provide time for locking screen
// now locking machine
SetClipboardContent();剪贴板在未锁定的会话上响应,但在计算机锁定时变为不可用,并返回“剪贴板锁定”错误(特定于语言)。
我已经测试了在google/stackoverflow中找到的几种与剪贴板相关的技术,用于上述语言(总共大约6种),到目前为止还没有一种有效。
机器在Windows 10企业版上运行(在3台相同版本的不同机器上测试)。
代码示例:
C#选项1:
using System.Windows.Forms;
.....
[STAThread]
static void Main()
{
System.Threading.Thread.Sleep(5000);
Clipboard.SetText("test copy clip");
}C#选项2(用于检查什么是锁定剪贴板):
[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选项1:
import pyperclip
import time
time.sleep(5)
pyperclip.copy('text')python选项2:
import win32clipboard
import time
time.sleep(5)
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText('text')
win32clipboard.CloseClipboard()VBA选项1:
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText "text for input"
clipboard.PutInClipboard发布于 2020-05-24 15:46:02
为此,您的后台进程应该在用户帐户中运行,并且应该在用户登录期间启动。
https://stackoverflow.com/questions/57095433
复制相似问题