奋斗在现在,输赢在将来

QTP脚本设计----学习笔记(二)

上一篇 / 下一篇  2012-03-13 09:29:56 / 个人分类:VBS

1.QTP调用外部程序的方法之一:systemUtil.Run "所需打开的程序路径","","",""

SystemUtil.Run"C:\type.txt","","",""

Window("Text:=type.txt - Notepad").Type"happy days"

Window("Text:=type.txt - Notepad").TypemicAltDwn &"F"& micAltUp

Window("Text:=type.txt - Notepad").TypemicLShiftDwn &"S"& micLShiftUp

Window("Text:=type.txt - Notepad").Close

 

2.QTP调用外部程序的方法之二:Wscript.Shell

------------------------------------------

'同时打开两个应用程序

option explicit

Dim objShell

Set bjShell=wscript.CreateObject("Wscript.Shell")

objShell.Run "notepad" '打开记事本

objShell.Run "calc" '打开计算器

------------------------------------------

 

------------------------------------------

'分次打开两个应用程序

option explicit

Dim objShell

Set bjShell=wscript.CreateObject("Wscript.Shell")

objShell.Run "notepad",,true '打开记事本

objShell.Run "calc" '打开计算器

------------------------------------------

 

3.VBS读取注册表:wshshell对象的regread方法

option explicit

Dim objShell,save

Set bjShell=wscript.CreateObject("Wscript.Shell")

save=objShell.regread("注册表的路径")

Wscript.echo save

set bjShell=nothing

 

4.VBS修改注册表中的关键字和值:wshshell对象的regwrite方法

option explicit

Dim path,objShell

path="注册表存放路径"

Set bjShell=wscript.CreateObject("Wscript.Shell")

objShell.regwrite(path&"需要替换的键值","替换后的键值")

Set bjShell=nothing

 

5.VBS删除注册表的关键字和值:wshshell对象的regdelete方法

-------同上-------

objShell.regdelete(path)

注意,如果要删除关键词的值的话一定要在路径最后加上“\”,如果不加斜线,就会删除整个关键词

 

6.VBS中创建文件对象:fso模型

Set fso=Wscript.CreateOject("scripting.filesystemobject")

Set fso=nothing

 

7.VBS对特殊文件的操作;getspecialfolder()

Set fso=Wscript.CreateObject("scripting.filesystemobject")

Set windFolfer=fso.getspecialfolder(0) '返回windows目录

Set windFolfer=fso.getspecialfolder(1) '返回system32\

Set windFolfer=fso.getspecialfolder(2) '返回临时目录

 

8.VBS中的sendkeys:

Set WshShell=WScript.CreateObject("WScript.Shell") 

WshShell.SendKeys "x"

------------SendKeys使用特殊字符来表示:Shift  ——  +Ctrl  ——  ^Alt  ——  %-------------

WshShell.SendKeys "^(ec) '按住Ctrl键的同时按下EC两个键

WshShell.SendKeys "^e"    '同时按下CtrlE

WshShell.SendKeys "^ec"   '同时按住CtrlE键,然后松开Ctrl键,单独按下“C”字母键

 

9.VBS中的AppActivate方法:AppActivate为寻找可执行程序的标题框

WshShell.AppActivate "无标题-记事本

 

 

 

 

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar