gutifeng 发表于 2012-4-26 11:15:20

WSCript.shell.run调用CMD,出错问题,解决办法!!

问题源代码如下:
Dim aaa
aaa="C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Set oShell = CreateObject("WSCript.Shell")
oShell.Run aaa,2,true
Set oShell = Nothing

参照QTP的HELP:Run Method的用法

解决后代码如下:
Dim oShell
Dim a
'C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe
a="cmd /K CD C:\Program Files\HP\QuickTest Professional\samples\flight\app\ & flight4a.exe"
Set oShell = CreateObject ("WSCript.shell")
oShell.run   a
Set oShell = Nothing

出现新问题:CMD窗口无法自动关闭
解决办法:oShell.run   a,0 (查看任务管理器,cmd.exe进程关闭)

snakeshiy 发表于 2012-4-26 17:44:23

写成这样试试
a = "cmd /c CD XXX"
页: [1]
查看完整版本: WSCript.shell.run调用CMD,出错问题,解决办法!!