如果不去挑战,你永远不知道自己的潜能到底有多大!

Msgbox的另一种替代(论坛转载)

上一篇 / 下一篇  2008-01-25 16:49:07 / 个人分类:QTP工具

Dim res, WSH
Set WSH = CreateObject("Wscrīpt.Shell")
res = WSH.Popup("Closed after 2 seconds.", 2)  '代替msgbox "Closed after 2 seconds"
Set WSH = Nothing

wscrīpt.shell 对象详细介绍!!

wshshell.createshortcut(strdesktop & "/a_key.lnk")
                omyshortcut.targetpath = "%windir%/notepad.exe"
                omyshortcut.hotkey = "alt+ctrl+f"
                omyshortcut.save
                wscrīpt.echo omyshortcut.hotkey = "alt+ctrl+f"

                请参阅
                wshspecialfolders 对象

                wshshortcut.iconlocation
                iconlocation 属性提供快捷方式对象的图标位置。图标位置的格式应为 "path,index"。

                语法
                wshshortcut.iconlocation = striconlocation

                wshshortcut.targetpath
                targetpath 属性提供快捷方式对象的目标路径。

                语法
                wshshortcut.targetpath = strtargetpath

                wshshortcut.windowstyle
                windowstyle 属性提供快捷方式对象的窗口样式。

                语法
                wshshortcut.windowstyle = natwindowstyle

                wshshortcut.workingdirectory
                workingdirectory 为一个快捷方式对象提供工作目录。

                语法
                wshshortcut.workingdirectory = strworkingdirectory

                wshshortcut.save
                save 方法把快捷方式对象保存到由 fullname 属性指定的位置。

                语法
                wshshortcut.save

        wshurlshortcut 对象
        该对象未直接给出。要获取 wshurlshortcut 对象,可使用 wshshell.createshortcut 方法。

        progid n/a
        文件名 wshom.ocx
        clsid  
        iid  


        下表说明了和 wshurlshortcut 对象有关的属性。

        属性 说明
        fullname url 快捷方式对象的完整路径。
        targetpath url 快捷方式对象的目标路径。


        下表说明了和 wshurlshortcut 对象有关的方法。

        方法 说明
        save 将快捷方式保存到指定的文件系统中。

                wshurlshortcut.fullname
                fullname 属性提供快捷方式对象的完整路径。

                语法
                wshurlshortcut.fullname = strfullname

                wshurlshortcut.targetpath
                targetpath 属性提供快捷方式对象的目标路径。

                语法
                wshurlshortcut.targetpath = strtargetpath

                wshurlshortcut.save
                save 方法保存一个快捷方式,该快捷方式指向 fullname 属性指定的位置。

                语法
                wshurlshortcut.save

wshshell.expandenvironmentstrings
expandenvironmentstrings 方法在 strstring 中扩展 process 环境变量并返回结果字符串。变量被 "%" 字符括起。

环境变量不区分大小写。

语法
wshshell.expandenvironmentstrings(strstring) = strexpandedstring

示例
msgbox "prompt is " & wshshell.expandenviromentstrings("%prompt%")



wshshell.popup
popup 方法显示一个弹出式消息框窗口,消息框中包含的消息由 strtext 指定。该消息框的窗口标题由 strtitle 指定。若 strtitle 省略,则窗口标题为 windows scrīpting host。

语法
wshshell.popup(strtext, , , ) = intbutton

注释
若提供 natsecondstowait 且其值大于零,则消息框在 natsecondstowait 秒后关闭。

nattype 的含义与其在 win32? messagebox 函数中相同。下表显示 nattype 中的值及含义。下表中的值可以组合。

按钮类型
值 说明
0 显示“确定”按钮
1 显示“确定”和“取消”按钮
2 显示“终止”、“重试”和“忽略”按钮
3 显示“是”、“否”和“取消”按钮
4 显示“是”和“否”按钮
5 显示“重试”和“取消”按钮


图标类型
值 说明
16 显示停止标记图标
32 显示问号图标
48 显示感叹号图标
64 显示信息标记图标


以上两个表并不涵盖 nattype 的所有值。完整的列表请参阅 win32 文档。

返回值 intbutton 指示用户所单击的按扭编号。若用户在 natsecondstowait 秒之前不单击按扭,则 intbutton 设置为 -1 。

值 说明
1 “确定”按扭
2 “取消”按扭
3 “终止”按扭
4 “重试”按扭
5 “忽略”按扭
6 “是”按扭
7 “否”按扭


示例
set wshshell = wscrīpt.createobject("wscrīpt.shell")
wshshell.popup "where do you want to go today?"

请参阅
wscrīpt.echo 方法

        wscrīpt.echo
        echo 方法在窗口(wscrīpt.exe 中)或“命令提示符”窗口(cscrīpt.exe 中)显示参数。

        参数用空格分隔。在 cscrīpt.exe 中,该方法在显示最后一个参数之后输出一对回车/换行(cr lf)。

        语法
        wscrīpt.echo

        示例
        wscrīpt.echo
        wscrīpt.echo 1, 2, 3
        wscrīpt.echo "windows scrīpting host is cool."

wshshell.regdelete
regdelete 从注册表中删除名为 strname 的键或值。

语法
wshshell.regdelete strname

参数
strname
如果 strname 以反斜杠 (/) 结束,则该方法删除键而不是值。
strname 参数必须以下列之一的根键名开始:

短根键名 长根键名
hkcu hkey_current_user
hklm hkey_local_machine
hkcr hkey_classes_root
hkey_users
hkey_current_config


示例
set wshshell = wscrīpt.createobject("wscrīpt.shell")

wshshell.regdelete "hkcu/scrīptengine/value"    " delete value "value"
wshshell.regdelete "hkcu/scrīptengine/key/"     " delete key "key"

请参阅
wshshell.regread 方法、wshshell.regwrite 方法


wshshell.regread
regread 方法返回名为 strname 的注册表键或值。

语法
wshshell.regread(strname) = strvalue

参数
strname
如果 strname 以反斜杠 (/) 结束,则该方法返回键,而不是值。
strname 参数必须以下列根键名开始。

short long
hkcu hkey_current_user
hklm hkey_local_machine
hkcr hkey_classes_root
hkey_users
hkey_current_config


注释
regread 方法仅支持 reg_sz、reg_expand_sz、reg_dword、reg_binary 和 reg_multi_sz 数据类型。若注册表有其他数据类型,regread 返回 disp_e_typemismatch。

示例
set wshshell = wscrīpt.createobject("wscrīpt.shell")

wshshell.regread("hkcu/scrīptengine/val")    " read from value "val"
wshshell.regread("hkcu/scrīptengine/key/")   " read from key "key"

请参阅
wshshell.regdelete 方法、wshshell.regwrite 方法


wshshell.regwrite
regwrite 方法设置名为 strname 的注册表键或值。

语法
wshshell.regwrite strname, anyvalue,

参数
strname
若 strname 以一个反斜杠 (/) 结束,则该方法设置键,而不是值。
strname 参数必须以下列根键名开头。

short long
hkcu hkey_current_user
hklm hkey_local_machine
hkcr hkey_classes_root
hkey_users
hkey_current_config



anyvalue
当 strtype 为 reg_sz 或 reg_expand_sz 时,regwrite 方法自动将 anyvalue 转换为字符串。若 strtype 为 reg_dword,则 anyvalue 被转换为整数。若 strtype 为 reg_binary,则 anyvalue 必须是一个整数。

strtype
regwrite 方法支持 strtype 为 reg_sz、reg_expand_sz、reg_dword 和 reg_binary。若其他的数据类型被作为 strtype 传递,regwrite 返回 e_invalidarg。
示例
set wshshell = wscrīpt.createobject("wscrīpt.shell")

wshshell.regwrite "hkcu/scrīptengine/value", "some string value"
wshshell.regwrite "hkcu/scrīptengine/key/", 1 "reg_dword"

请参阅
wshshell.regdelete 方法、wshshell.regwrite方法


wshshell.run
run 方法创建一个新的进程,该进程以 intwindowstyle 窗口样式执行 strcommand。

语法
wshshell.run (strcommand, , )

参数
strcommand
在 strcommand 参数内部的环境变量被自动扩展。

intwindowstyle
这是为新进程在 startupinfo 结构内设置的 wshowwindow 元素的值。其意义与 showwindow 中的 ncmdshow 参数相同,可取以下值之一。名称 值 含义
sw_hide
0 隐藏窗口并激活另一窗口。
sw_minimize
6 最小化指定窗口并激活按 z 序排序的下一个顶层窗口。
sw_restore
9 激活并显示窗口。若窗口是最小化或最大化,则恢复到原来的大小和位置。在还原应用程序的最小化窗口时,应指定该标志。
sw_show
5 以当前大小和位置激活并显示窗口。
sw_showmaximized
3 激活窗口并以最大化显示该窗口。
sw_showminimized
2 激活窗口并以最小化显示该窗口。
sw_showminnoactive
7 最小化显示窗口。活动窗口保持活动。
sw_showna
8 以当前状态显示窗口。活动窗口保持活动。
sw_shownoactivate
4 按窗口最近的大小和位置显示。活动窗口保持活动。
sw_shownormal
1 激活并显示一个窗口。若窗口是最小化或最大化,则恢复到其原来的大小和位置。



blnwaitonreturn
如果未指定 blnwaitonreturn 或其值为 false,则该方法立即返回到脚本继续执行而不等待进程结束。
若 blnwaitonreturn 设为 true,则 run 方法返回由应用程序返回的任何错误代码。如果未指定 blnwaitonreturn 或其值为 false,则 run 返回错误代码 0(zero)。

示例
" this fragment launches notepad with the current executed scrīpt
  set wshshell = wscrīpt.createobject("wscrīpt.shell")
  wshshell.run ("notepad " & wscrīpt.scrīptfullname)
  wshshell.run ("%windir%/notepad" & wscrīpt.scrīptfullname)

" this fragment returns the error code from the executed application
  return = wshshell.run("notepad " & wscrīpt.scrīptfullname, 1, true)

 


TAG: QTP工具

 

评分:0

我来说两句

Open Toolbar