我正在尝试向电子表格添加一个按钮,单击该按钮会将特定的URL复制到剪贴板.
我对Excel VBA有一点了解,但已经有一段时间了,我正在努力.
我正在构建一个进程(到目前为止,我已经在 .Net Framework 4.7.2 上尝试过 VBA、Python 和 C#),它需要在锁定屏幕后面的 Windows 10 机器上将一些字符串放入剪贴板。为了测试,我将它减少到只有两个命令(伪代码,因为使用了 3 种语言。问题末尾的详细信息):
SleepForFiveSec(); //to provide time for locking screen
// now locking machine
SetClipboardContent();
Run Code Online (Sandbox Code Playgroud)
剪贴板对解锁会话有响应,但在机器锁定时变得不可用并返回“剪贴板锁定”错误(特定于语言)。
我已经测试了在 google/stackoverflow 中找到的几种与剪贴板相关的技术,用于提到的语言(总共大约 6 种),但到目前为止都没有奏效。
机器在 Windows 10 Enterprise 上运行(在 3 台具有相同版本的不同机器上测试)。
代码示例:
C# 选项 1:
using System.Windows.Forms;
.....
[STAThread]
static void Main()
{
System.Threading.Thread.Sleep(5000);
Clipboard.SetText("test copy clip");
}
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud)