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

查看:27
本文介绍了如何在 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 资源管理器在右键单击上所做的那样/复制).

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 上找到了 this,它在一个小程序中使用 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.

我看到一些参考资料,例如 this 表示剪贴板在 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.

这是一个代码片段(输出是一个文本流)

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

    Set ie = CreateObject("InternetExplorer.Application") 
ie.Visible = 0
ie.Navigate2 "C:UsersDavid CandyDesktopFilter.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天全站免登陆