如何在vbscript中使用剪贴板? [英] How can I use Clipboard in vbscript?

查看:93
本文介绍了如何在vbscript中使用剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编者注

这个问题是专门关于将文件引用复制到剪贴板的,但其通用标题导致了答案关于如何复制/获取文本

Editor's note:
While this question is specifically about copying a file reference to the clipboard, its generic title led to answers about how to copy / get text.

作为Windows上的Emacs用户,经常在邮件中附加文件,我一直寻找一种实用程序将文件(不是其内容)复制到剪贴板,就像Windows资源管理器在righclick / copy上所做的一样。

As an Emacs user on Windows who often attaches files in mails, I have been looking for a utility to copy a file (not its contents) to the clipboard, just as windows explorer does on righclick/copy).

我只是在SO上找到,它在一个小程序中使用System.Windows.Forms.Clipboard`来做到这一点。但这是用C#语言编写的,因此我无法立即访问其编译器。所以我想知道是否可以做到这一点以及如何做到。

I just found this right here on SO which uses System.Windows.Forms.Clipboard` in a small program to do exactly that. But it is in C#, for which I don't have immediate access to a compiler. So I am wondering if this can be done and how.

我看到了一些引用,例如在VBScripting中无法访问,但msdn 显示了VB文档,所以我冒这个问题的风险。

I saw several references such as this that the clipboard is not accessible in VBScripting, but msdn shows documentation for VB so I am risking the question.

我以前从未写过VBScript,但是在询问之前我确实尝试了一些事情,首先运行粘贴有 Hello world的副本,然后运行 CreateObject 的各种组合

I have never written a VBScript before but I did try a few things before asking, starting with running a copy pasted a "Hello world" and then various combinations of CreateObject etc.

更新:我需要致电 Clipboard.SetFileDropList ,所以我认为我不能使用 ClipboardData 如答案所示,它没有此方法。

Update: I need to call Clipboard.SetFileDropList, so I do not think I can use ClipboardData as suggested by the answers, it does not have this method.

访客更新

我最终使用的解决方案是编译 C#本身,我不知道我已经有了编译器。

The solution I ended up using was to compile the C# itself, I did not know I already had a compiler.

访问者的另一项更新
https://stackoverflow.com/a/29963268/18573 是我现在正在使用的,

Another update for visitors https://stackoverflow.com/a/29963268/18573 is what I am now using, quite happily.

推荐答案

VBScript不支持剪贴板。承载vbscript的大多数主机(例如Internet Explorer)都可以通过该主机进行访问。因此,在IE或HTA中运行的vbscript可以使用IE的剪贴板支持。脚本宿主不提供剪贴板支持。您可以使用vbs文件通过COM自动化启动IE,浏览到本地页面(以绕过安全警告),然后使用IE的剪贴板。

VBScript doesn't support the clipboard. Most hosts that host vbscript, such as Internet Explorer give access through the host. Therefore vbscript running in IE or an HTA can use IE's clipboard support. The scripting hosts do not give clipboard support. You can use a vbs file to start IE through COM automation, navigate to a local page (to bypass security warnings), then use IE's clipboard.

下面是一个代码片段( Outp。是文本流)

Here's a code snippit (Outp. is a text stream)

    Set ie = CreateObject("InternetExplorer.Application") 
ie.Visible = 0
ie.Navigate2 "C:\Users\David Candy\Desktop\Filter.html"
Do 
    wscript.sleep 100
Loop until ie.document.readystate = "complete"  
txt=ie.document.parentwindow.clipboardData.GetData("TEXT")
ie.quit
If IsNull(txt) = true then 
    outp.writeline "No text on clipboard"
else
    outp.writeline txt
End If

这篇关于如何在vbscript中使用剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆