【发布时间】:2016-09-12 17:10:26
【问题描述】:
我想检查是否在 vbscript 中使用通配符打开了一个窗口。我能够找到下面的代码:
Set oShell = CreateObject("WScript.Shell")
If oShell.AppActivate("Untitled - Notepad") Then
WScript.Sleep 500
End If
但我想在窗口标题上使用通配符。我尝试使用 * 和 % 但它不起作用。任何帮助表示赞赏。
If oShell.AppActivate("*Notepad*") Then
更新家伙..我能够找到一个解决方案,但如果有人可以简化它,它仍然是开放的。谢谢。
Set Word = CreateObject("Word.Application")
Set Tasks = Word.Tasks
isFound = False
For i = 1 to 5
For Each Task in Tasks
checkVal = 0
If Task.Visible Then
checkVal = inStr(UCase(Task.name), UCase("outlook"))
If checkVal <> 0 Then
isFound = True
Exit For
End If
End If
Next
If isFound = True Then
Exit For
End If
WScript.Sleep 1000
Next
Word.Quit
msgbox ("Is the Window Found? - " & isFound)
【问题讨论】:
-
这不是一个可以用来获取它的本地安装库。有一些库/包装器可以让您实现这一目标,但如果不获取/编码额外的库,您将无法从原始 VBScript 实现这一目标。您可以尝试使用带有 shell 的 TASKLIST 执行标准输出捕获,例如 tasklist /v | find /i "在这里搜索字符串"
-
另外...您可以使用正则表达式从该任务列表输出中捕获窗口标题字段。 (?:.*)(?:\d:\d\d:\d\d\s)(.*)
-
嗨史蒂夫 - 我试图找到一个使用正则表达式的解决方案,但幸运的是我能够找到一些解决方案,我已经更新了我上面的问题。顺便说一句,我就是这样做的,我得到了任务列表上的所有名称并在其上循环以使用 inStr 函数找到我正在寻找的字符串。
-
有一种比创建 word 文档更快的方法......请参阅下面的答案。
-
AppActivate 已经有一个隐含的通配符。
In determining which application to activate, the specified title is compared to the title string of each running application. If no exact match exists, any application whose title string begins with title is activated. If an application still cannot be found, any application whose title string ends with title is activated. If more than one instance of the application named by title exists, one instance is arbitrarily activated.
标签: vbscript