【问题标题】:Saving snapshot using vbscript使用 vbscript 保存快照
【发布时间】:2012-04-10 02:46:14
【问题描述】:

我是 vbscript 的新手。我想保存使用 vbscript 打开的 Internet Explorer 窗口的 vbscript 拍摄的快照。

加载页面的代码

Dim IE, stateString
Set IE = WScript.CreateObject("InternetExplorer.Application")
ie.toolbar = 1
ie.statusbar = 1
ie.width = 999
ie.height = 500
ie.left = 20
ie.theatermode = false
ie.theatermode = true
ie.theatermode = false
ie.top = 50
ie.navigate("file:///C:\Users\Vinit_Tiwari\Documents\vbscripts\someform.html")
'stateString = cstr(ie.readystate)
waitforload(ie)


ie.visible = 1

Set wshShell = CreateObject("Wscript.Shell")

wshShell.AppActivate "Some Form"
wshShell.SendKeys "% x"

拍摄快照的代码

Dim oWordBasic
set oWordBasic = CreateObject("Word.Basic")
oWordBasic.sendkeys "{prtsc}"
oWordBasic.AppClose "Microsoft Word"
Set oWordBasic = Nothing
Wscript.Sleep 2000

保存快照

dim paint
set paint = wshShell.exec("mspaint")
do while paint.status = 0:loop
wshShell.appactivate("untitled-Paint")'this returns false
Wscript.sleep 500
WshShell.SendKeys "^v"
wscript.sleep 500
wshshell.sendkeys "^s"
wscript.sleep 500
wshshell.sendkeys "d:\test.png"
wscript.sleep 500
wshell.sendkeys "{Enter}"
Set wshshell = Nothing

实际上之前打开的 ie 窗口具有焦点,并且击键被发送到 ie 而不是绘制。那么是否有任何功能可以执行AppActivate的相反工作。

【问题讨论】:

    标签: vbscript automation screenshot clipboard browser-automation


    【解决方案1】:

    这行不通。按下 Print Screen 按钮时,Microsoft Word 处于焦点位置。您可以通过完全不使用 Microsoft Word 轻松消除此问题。这不是必需的。 Print Screen 功能是系统热键,与 Microsoft Word 无关。您应该使用 Alt+PrintScreen 组合将当前聚焦窗口的屏幕截图捕获到剪贴板。

    其次,如果Paint而不是IE不在焦点,那是因为你的窗口标题错误。你正在正确地做那部分。如果 AppActivate 找不到具有指定标题的窗口,则返回 false。老实说,Paint 应该已经有了焦点,但最好先确保窗口被激活。

    另外,这是一个非常古老的系统吗?出于好奇,您为什么还要使用 Word.Basic 自动化对象?

    【讨论】:

    • 您好 Nilpo,感谢您的回复...但您能否告诉我在 AppActivate 中传递的正确标题是什么,以便应用程序可以在前台运行...跨度>
    • 每个版本的 Windows 都不同。您需要打开 MS Paint 并查看标题栏。
    • 实际上我使用的是 Windows 7,标题栏显示 mspaint 的“Untitled-Paint”,这就是我正在尝试的。
    • 单词之间通常有空格...“Untitled - Paint”
    • 有同样的问题,关于 Word.Basic,我也不得不使用它,因为 Printscreen 不能用作 Vbscript 中的发送键,但它可以在 Word.Basic 中,这是我的唯一原因还是用吧
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 2020-01-16
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多