【问题标题】:How to clear Windows clipboard using a batch file or PowerShell?如何使用批处理文件或 PowerShell 清除 Windows 剪贴板?
【发布时间】:2019-07-28 17:46:27
【问题描述】:

我有一个批处理文件,我的程序会自动使用剪贴板。

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

echo>nul|clip

还有其他清除Windows剪贴板的方法吗?

【问题讨论】:

  • < nul clip 呢?
  • break|clip(清除剪贴板中的文本;如果有图片(或者可能是除文本之外的任何对象)则无效)(@aschipfl 你的不起作用(令人惊讶))
  • 什么? rem/ | clip 工作吗? (目前无法测试,我在手机上)
  • @aschipfl:对不起,没有:Der Befehl "rem/" ist entweder falsch geschrieben oder konnte nicht gefunden werden.(只是rem/,没有管道工程)
  • 谢谢,@Stephan! (rem/) | clip 将起作用; < nul clip 失败绝对不合逻辑,多么糟糕的设计!

标签: windows powershell batch-file cmd clipboard


【解决方案1】:

嗯,最合乎逻辑的方法(至少在我看来),就是 redirect (<) nothing (nul) 到 STDIN (handle 0) 到clip 命令,如 < nul clip,由于该命令的糟糕设计而无法工作,因为输入重定向 (<) 似乎只能对文件进行。

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

echo/> nul | clip

break | clip

(rem/) | clip

type nul | clip

goto | clip

call | clip

exit | clip

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

【讨论】:

  • 使用 powershell 时,上述命令均无效。我们应该使用 cmd 来运行这些命令。
  • 是的,@ToughMind,这是cmdbatch-file 的代码,就像问题中的代码一样;其他答案已经提供powershell 解决方案...
【解决方案2】:

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

powershell -NoLogo -NoProfile -Command "Set-Clipboard -Value $null"

【讨论】:

    【解决方案3】:

    如果你想用 Powershell 来做:

    Add-Type -AssemblyName System.Windows.Forms
    [System.Windows.Forms.Clipboard]::Clear()
    

    【讨论】:

      【解决方案4】:

      批次

      更多的批处理方式:

      <nul set /p="" | clip
      dir >nul | clip 
      cd %cd% | clip
      pushd %cd% | clip
      cd >nul | clip
      

      VBscript

      VBscript 中的一个方法:

      Dim IE
      Set IE = CreateObject("InternetExplorer.Application")
      IE.Navigate("about:blank")
      IE.Document.ParentWindow.ClipboardData.SetData "text", ""
      IE.Quit
      

      【讨论】:

        猜你喜欢
        • 2012-05-10
        • 1970-01-01
        • 2015-12-20
        • 2010-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-29
        • 1970-01-01
        相关资源
        最近更新 更多