點擊開始->運行,輸入:
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.這里不再贅述。
文章來源于領測軟件測試網 http://www.kjueaiud.com/