如何使用批处理文件或 PowerShell 清除 Windows 剪贴板?

2 windows clipboard powershell cmd batch-file

我有一个批处理文件,我的程序会自动与剪贴板一起工作。

但我想清除剪贴板并使用它:

echo>nul|clip
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以清除 Windows 剪贴板?

lit*_*lit 9

这是另一种方法。这似乎至少清除了 CF_TEXT 和 CF_BITMAP。需要测试以查看它是否清除所有 CF_* 类型。

powershell -NoLogo -NoProfile -Command "Set-Clipboard -Value $null"
Run Code Online (Sandbox Code Playgroud)


asc*_*pfl 5

好吧,最合乎逻辑的方法(至少在我看来),即重定向( <) 没有 ( nul) 到STDIN(句柄0)到clip命令,例如< nul clip,由于该命令的设计糟糕而不起作用,因为看起来输入重定向 ( <) 只能对文件进行。

所以|需要使用管道(),它仍然允许几种方式:

echo/> nul | clip

break | clip

(rem/) | clip

type nul | clip

goto | clip

call | clip

exit | clip
Run Code Online (Sandbox Code Playgroud)

以上所有方法都使用管道左侧的命令,该命令不会向STDOUT (handle 1)输出任何内容。


tec*_*029 5

如果你想使用 Powershell 来执行此操作:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Clipboard]::Clear()
Run Code Online (Sandbox Code Playgroud)