在Silktest中自动添加打印机

发表于:2007-4-05 14:17

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Whisper    来源:网络

首先来看一个动态连接库文件: Printui.dll
点击开始->运行,输入:
rundll32 printui.dll,PrintUIEntry [options] [@commandfile]

Rundll32.exe 可以帮助我们运行dll文件,printui.dll后面的逗号,其实说明的是入口点:PrintUIEntry。
后面的选项以及@commandfile详情只要输入
rundll32 printui.dll,PrintUIEntry /?
即可


在自动测试的过程中,我们经常会遇到这样一种情况:

在遍历dialog的时候,需要测试有/无安装打印机时软件的反馈。
那么在Silktest中怎么实现呢?

在Silktest中,有一个命令:Sys_Execute:
Syntax
iReturn = SYS_Execute (sCmdLine [, lsOutput])

iReturn :The return value of the command. INTEGER.
sCmdLine :The command to execute. STRING.
lsOutput :[Optional.] A variable to hold any text written to stdout when sCmdLine runs. LIST OF STRING.

这个命令执行一个命令行命令。并且把退出结果返回给返回值。所有的命令输出被写入IsOutput。简单的说,你可以把这个命令完全当作windows的命令行工具来用,他就和Windows键+R 一个效果。
说道这里大家肯定都想到了:利用这个命令,利用Windows Rundll32.dll,调用Printui.dll的函数,就可以拉。于是非常简单的:

[-] void AddNetworkPrinter (string printername)
[ ]SYS_Execute("Rundll32 printui.dll,PrintUIEntry /in /n {printername}")

这个函数将调运Rundll32 通过它访问printui.dll的PrintUIEntry函数,传递 /in /n {printername} 其中{printername}是你在定义里给出的string pritername

当然,除了Sys_Execute我们还有其他的方法。(实际情况是,SYS_EXECUTE这个函数,不怎么完善...) 我们可以在silktest的脚本中,直接加载dll,因此有如下方法:

[-] dll "kernel32.dll"
[ ] //INT WinExec (String sPath, int iWinType)
[ ] INT WinExec (LPCSTR sPath, UINT iWinType)
[-] void AddNetworkPrinter (string printername)
[ ] // Example: AddNetworkPrinter("\\printserver\printer")
[ ] Winexec("rundll32 printui.dll,PrintUIEntry /in /n{printerName}", SW_SHOWMINIMIZED)

其实都是一样的。只是列在这里说明使用dll "xxxx.dll"的方法。其中的 WinExec,可以自行参照MSDN.这里不再赘述。

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号