无效的窗口句柄,错误代码:80070578

时间:2016-05-10 10:22:03

标签: vbscript

我在下面用vb脚本编写了一个窗口并将其置于焦点

Dim oShell
Set oShell = CreateObject("WScript.Shell")
'bring the window to front
'title must be exactly what you see in the titlebar of the window
oShell.AppActivate WScript.Arguments(0)

我从java代码中调用这个vb脚本:

Runtime.getRuntime().exec("cmd.exe /c activeWindow.vbs mywindowname");

现在有时它会把这个抛到异常之下:

enter image description here

这是随机发生的。

1 个答案:

答案 0 :(得分:0)

AppActivate的语法: objShell.AppActivate strApplicationTitle

下面的代码直接通过传递标题名称 Dim oShell Set oShell = CreateObject("WScript.Shell") oShell.AppActivate "Calculator"

或作为参数传递" WScript.Arguments(0)"。将此代码保存在VBS文件

Dim oShell Set oShell = CreateObject("WScript.Shell") oShell.AppActivate WScript.Arguments(0) WScript.Quit 0

来自cmd类型wscript Sample.vbs Calculator

代码工作正常,计算器屏幕正在激活。