windows 使用 VBScript 清除剪贴板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2396109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:05:13  来源:igfitidea点击:

Clearing the clipboard using VBScript

windowsvbscriptclipboard

提问by user288181

How can the clipboard be cleared using VBScript on Win32?

如何在 Win32 上使用 VBScript 清除剪贴板?

回答by Peter Mortensen

It can not be done directly, but you can let an application do the work. This will clear the clipboard, using the command-line tool clip:

它不能直接完成,但您可以让应用程序完成工作。这将使用命令行工具清除剪贴板clip

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True


Another way is to use applications that have a COMinterface and that can manipulate the clipboard. E.g. Microsoft Word and Internet Explorer.

另一种方法是使用具有COM接口并且可以操作剪贴板的应用程序。例如 Microsoft Word 和 Internet Explorer。

This will work, using Internet Explorer, but it may throw a user dialog:

这将工作,使用 Internet Explorer,但它可能会抛出一个用户对话框:

Set slaveApplication = CreateObject("InternetExplorer.Application")
slaveApplication.Navigate("about:blank")
slaveApplication.document.parentwindow.clipboardData.SetData "text", ""
slaveApplication.Quit