Board logo

标题: 请教VBS sendkey问题? (已结案) [打印本页]

作者: pdanniel66     时间: 2010-1-8 04:59    标题: 请教VBS sendkey问题? (已结案)

请教VBS  sendkey问题
因为应用程序异常,会跳出错误窗口,窗口title是“SAP_ERPRoute.exe - Common Language Runtime 侦错服务",此时只须按下<Enter>键,程序可以继续运作,所以写了以下VBS,设定windows 工作排程,5分钟执行1次,可以暂时解决程序异常问题。但是后来发现,当程序未出现错误时,每5分钟执行的windows 工作排程,会自动按下当时 Active的窗口,若是记事本打开且Active时,会被按下 <Enter>,等同跳行,若是鼠标停在关机,虽然没按 Click , 若5分钟时间一到,会被关机。以下 VBS script不是有指定窗口Title "SAP_ERPRoute.exe - Common Language Runtime 侦错服务",应该只会针对该Title按下 <Enter>,哪里写错了,请教大家,谢谢!

Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")   
WshShell.AppActivate "SAP_ERPRoute.exe - Common Language Runtime 侦错服务"
WshShell.SendKeys "{ENTER}"

[ Last edited by pdanniel66 on 2010-1-9 at 17:24 ]
作者: pdanniel66     时间: 2010-1-8 06:45    标题: 使用if 似乎可以 work,但想要记录Log

使用if 似乎可以 work,但想要记录Log, Wscript.Echo  " SAP_ERPRoute.exe - Common Language Runtime 侦错服务active" > 999.txt 语法似乎错误,如下所示,请帮忙! Thanks!

Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")   
WshShell.AppActivate "SAP_ERPRoute.exe - Common Language Runtime 侦错服务"
if WshShell.appactivate("SAP_ERPRoute.exe - Common Language Runtime 侦错服务") = true Then
wscript.sleep 3000
WshShell.SendKeys "{ENTER}"
Wscript.Echo  " SAP_ERPRoute.exe - Common Language Runtime 侦错服务active" > 999.txt
End If
作者: pdanniel66     时间: 2010-1-9 17:20    标题: I have the solution as below.

vbs_enter.bat

dir D:\scripts\TEST\20100106_vbs_enter\writeoutput.txt || echo SAP-MQ Error Log Start Here > D:\scripts\TEST\20100106_vbs_enter\writeoutput.txt
cscript /Nologo D:\scripts\TEST\20100106_vbs_enter\vbs_en_20100109_v2.vbs
cscript /Nologo D:\scripts\TEST\20100106_vbs_enter\vbs_en_20100109_v3.vbs

vbs_en_20100109_v2.vbs as below:

Dim WshShell
Const ForAppending = 8
Set WshShell=WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("D:\scripts\TEST\20100106_vbs_enter\writeoutput.txt", ForAppending)
objFile.WriteLine "Error Log -- Date: " & Now() & vbCrLf
WshShell.AppActivate "SAP_ERPRoute.exe - Common Language Runtime 侦错服务"
if WshShell.appactivate("SAP_ERPRoute.exe - Common Language Runtime 侦错服务") = true Then
objFile.WriteLine "SAP_ERPRoute.exe - Common Language Runtime 侦错服务"    & Now()
objFile.WriteLine vbCrLf
objFile.Close
wscript.sleep 3000
WshShell.SendKeys "{ENTER}"
'Wscript.Echo  "test123.txt active" > 999.txt
End If


vbs_en_20100109_v3.vbs as below :
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "SAP_ERPRoute.exe - Common Language Runtime 侦错服务"
if WshShell.appactivate("SAP_ERPRoute.exe - Common Language Runtime 侦错服务") = true Then
wscript.sleep 3000
WshShell.SendKeys "{ENTER}"
'Wscript.Echo  "test123.txt active" > 999.txt
End If

[ Last edited by pdanniel66 on 2010-1-9 at 19:38 ]
作者: pdanniel66     时间: 2010-1-9 20:07    标题: We can hide the batch DOS window.

start_batch.vbs

Dim Wsh
Set Wsh = WScript.CreateObject("WScript.Shell")
WScript.Sleep(5000)
Wsh.Run "D:\scripts\TEST\20100106_vbs_enter\vbs_Enter_v1.bat",false,false
Set Wsh=NoThing
WScript.quit