SystemUtil Object Descrīption
An object used to control applications and processes during a run session.
在腳本運行過程中,可使用該對象控制應用程序或進程.
Operations
The tables below list the built-in methods and properties that you can use as operations for the SystemUtil object. 下表列出了SystemUtil對象的內建方法與屬性.
Methods BlockInput Prevents keyboard and mouse input events from reaching applications.
禁止鍵盤或鼠標操作.
CloseDescendentProcesses Closes all processes opened by QuickTest.
關閉由QuickTest打開的所有進程.
CloseProcessByHwnd Closes a process that is the owner of a window with the specified handle.
根據窗口的句柄找到相應的進程,并關閉該進程.
CloseProcessById Closes a process according to its Process ID (PID).
關閉指定進程PID的進程.
CloseProcessByName Closes a process according to its name.
關閉指定進程名稱的進程.
CloseProcessByWndTitle Closes all processes that are owners of windows with the specified title.
關閉指定窗口標題的進程.
Run Runs a file or application.
運行文件或應用程序.
UnblockInput Re-enables keyboard and mouse input events after a BlockInput statement
was used to block them.
在BlockInput語句禁止鍵盤或鼠標之后,使用UnblockInput語句可解除對鍵盤或
鼠標的禁止.
BlockInput Method Descrīption
Prevents keyboard and mouse input events from reaching applications.
禁止鍵盤或鼠標操作.
Syntax object.BlockInput
Argument Descrīption
Object A test object of type SystemUtil.
SystemUtil類型的測試對象.
Return Value
None
Remarks
You can use this method to prevent a run session being accidentally interrupted by someone using the keyboard or mouse on a QuickTest Professional computer.
當電腦正在運行QTP腳本時,使用BlockInput方法可以防止因鍵盤或鼠標的操作擾亂QTP的正常運行.
After using this method, keyboard and mouse input is blocked until one of the following occurs:
使用BlockInput方法后,使用以下方法可以解除對鍵盤或鼠標的禁止:
An UnblockInput statement is used
當使用了UnblockInput語句后.
A run session ends or is paused for any reason (end of test run, run error, breakpoint, and so forth)
當腳本運行結束或中斷(如整個test結束,運行錯誤,斷點等等).
The Ctrl+Alt+Delete key combination is pressed on the keyboard
在鍵盤上按下Ctrl+Alt+Delete結合鍵后.
A critical system error occurs
當出現了嚴重的系統錯誤時.
Example
Block Keyboard and Mouse Input During a Run Session
下面的例子使用BlockInput方法,在QTP腳本運行過程中禁用了鍵盤及鼠標.
Sub BlockInput_Example()
SystemUtil.BlockInput
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set
"mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury
Tours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2,
2 、SystemUtil.UnblockInput
End Sub
UnblockInput Method
Descrīption
Re-enables keyboard and mouse input events after a BlockInput statement was used to block them.
在BlockInput語句禁止鍵盤或鼠標之后,使用UnblockInput語句可解除對鍵盤或鼠標的禁止.
Syntax
object.UnblockInput
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類型的測試對象.
Return Value
None
Remarks
You can use this method to unblock keyboard and mouse input that was earlier blocked using a BlockInput
statement.
如果先前使用了BlockInput方法禁止了鍵盤及鼠標,使用UnblockInput方法可解除禁止.
Example
Unblock Keyboard and Mouse Input That Was Previously Blocked
本例在開始使用BlockInput方法禁止了鍵盤及鼠標,后來使用UnblockInput方法解除了禁止.
Sub UnblockInput_Example()
SystemUtil.BlockInput
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set
"mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury
Tours").WebEdit("password").SetSecure "4082986e39ea469e70dbf8c5a29429fe138c6efc"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 2,
2
SystemUtil.UnblockInput
End Sub
CloseDescendentProcesses Method
Descrīption
Closes all processes opened by QuickTest.
關閉由QuickTest打開的所有進程.
Syntax
object.CloseDescendentProcesses
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類型的測試對象.
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個長整型值.被CloseDescendentProcesses方法語句關閉的程序實例數.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執行該語句時,QuickTest首先向進程窗口發送一個WM_CLOSE信息,償試關閉該進程;如果該進程在5秒鐘后存未
關閉,則QuickTest強制結束進程.
Example
Close All Applications Opened By QuickTest
在本例中:假定在運行程序之初,Record and Run對話框自動打開了某個窗口,然后通過Run語句打開了一個NotePad窗口,
那么該CloseDscendentProcessed方法的返回值就就該是2,因此Message對話框顯示的信息應該是"2".
Sub CloseDescendentProcesses_Example()
SystemUtil.Run "Notepad.exe"
MsgBox SystemUtil.CloseDescendentProcesses
End Sub
CloseProcessByHwnd Method
Descrīption
Closes a process that is the owner of a window with the specified handle.
根據窗口的句柄找到相應的進程,并關閉該進程.
Syntax
object.CloseProcessByHwnd (hWnd)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類型的測試對象.
hWnd Required. An ULong object.
The handle of the window owned by the process you want to close.
Tip: You can retrieve the window handle using the hwnd property. For
example:
Window("MyAppName").GetROProperty("hwnd")
必須.一個ULong對象.
你想要關閉的進程的窗口的句柄.
Tip:你可以通過獲取Runtime窗口對象的hwnd屬性值來獲得句柄信息.例如:
Window("MyAppName").GetRoProperty("hwnd")
Return Value
A Boolean value.
一個Boolean值.
True--The specified process was successfully closed.
True――指定的進程已被成功關閉.
False--The specified process was not closed.
False――指定的進程未被關閉.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執行該語句時,QuickTest首先向進程窗口發送一個WM_CLOSE信息,償試關閉該進程;如果該進程在5秒鐘后存未
關閉,則QuickTest強制結束進程.
Example
Close the Process that is an Owner of a Window with the Specified Handle
在本例中,首先通過GetroProperty方法獲取NotePad窗口的句柄,然后使用CloseProcessByHwnd方法關閉Notepad程序.
Sub CloseProcessByHwnd_Example()
hWnd = Window("Notepad").GetROProperty("hwnd")
SystemUtil.CloseProcessByHwnd (hWnd)
End Sub
CloseProcessById Method
Descrīption
Closes a process according to its Process ID (PID).
根據進程的Process ID(PID)關閉進程.
Syntax
object.CloseProcessById (wdProcessId)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類型的測試對象.
wdProcessId Required. An ULong object.
The Process ID (PID) of the process you want to close.
Tip: You can find the PID of an application by viewing the value in the
Processes tab of the Windows Task Manager, or you can retrieve the value
using the process id property. For example:
Window("MyAppName").GetROProperty("process id")
必須.一個ULong對象.
你想關閉的進程的PID.
Tip:在Windows的任務窗口的進程標簽頁可以查看到程序的PID值,你也可以通
過獲取Runtime窗口對象的Process id屬性值來獲得PID信息.例如:
Window("MyAppName").GetRoProperty("process id")
Return Value
A Boolean value.
一個Boolean值.
True--The specified process was successfully closed.
True――指定的進程已被正常關閉.
False--The specified process was not closed.
False――指定的進程未被關閉.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執行該語句時,QuickTest首先向進程窗口發送一個WM_CLOSE信息,償試關閉該進程;如果該進程在5秒鐘后存未
關閉,則QuickTest強制結束進程.
Example
Close an Application According to its Process ID
下面的例子通過GetRoProperty方法獲取Notepad窗口的PID值,然后使用CloseProcessById方法關閉Notepad程序.
Sub CloseProcessById_Example()
PID = Window("Notepad").GetROProperty("process id")
SystemUtil.CloseProcessById (PID)
End Sub
CloseProcessByName Method
Descrīption
Closes a process according to its name.
Syntax
object.CloseProcessByName (bsProcessName)
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類型的測試對象.
bsProcessName Required. A String value.
The name of the process you want to close.
必須.一個字符串值.
你想關閉的進程的名稱.
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個Long值.所關閉的程序的實例數.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執行該語句時,QuickTest首先向進程窗口發送一個WM_CLOSE信息,償試關閉該進程;如果該進程在5秒鐘后存未
關閉,則QuickTest強制結束進程.
Example
Close All Instances of a Specified Application
本例通過CloseProcessByName方法,關閉所有已打開的Notepad實例.如果當前所有的Notepad實例都是由下面的Run語句打開的,則CloseProcessByName方法語句會關閉這些實例,并且MsgBox窗口顯示的數值應為"3".
Sub CloseProcessByName_Example()
SystemUtil.Run "Notepad.exe"
SystemUtil.Run "Notepad.exe"
SystemUtil.Run "Notepad.exe"
MsgBox SystemUtil.CloseProcessByName("Notepad.exe")
End Sub
CloseProcessByWndTitle Method
Descrīption
Closes all processes that are owners of windows with the specified title.
關閉指定窗口標題的所有進程.
Syntax
object.CloseProcessByWndTitle (bsTitle, [bRegExp])
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類型的測試對象.
bsTitle Required. A String value.
The title of the window owned by the process you want to close.
必須.一個字符串值.
你想關閉的進程的窗口的標題.
bRegExp Optional. A Boolean value.
Indicates whether the bsTitle argument is treated as a regular
expression. Default = False.
可選.一個Boolean值.
檢查BsTitle參數是否是一個正則表達式.默認值為False.
Return Value
A Long value. The number of instances of the application that are closed when the statement runs.
一個Long值.被語句所關閉的程序的實例數.
Remarks
Note: QuickTest initially tries to close the process by sending a WM_CLOSE message to the process window. If
the process is still open after 5 seconds, QuickTest terminates the process.
注意:執行該語句時,QuickTest首先向進程窗口發送一個WM_CLOSE信息,償試關閉該進程;如果該進程在5秒鐘后存未關閉,則QuickTest強制結束進程.
Example
Close All Windows with a Title Containing a Specified String
本例關閉了所有的標題包含有"Notepad"字樣的頂層窗口.因為bRegExp參數值為"ture",表示bsTitle值是一個正則表達式.
Sub CloseProcessByWndTitle_Example1()
SystemUtil.CloseProcessByWndTitle "Notepad", True
End Sub
Close All Windows in which the Exact Title Matches a Specified String
本例關閉所有窗口標題為"Untitled-Notepad"的頂層窗口.因為bRegExp參數值為"false",表示bsTitle參數值是一個文字串,因此窗口標題必須與參數值精確匹配.
Sub CloseProcessByWndTitle_Example2()
SystemUtil.CloseProcessByWndTitle "Untitled - Notepad"
End Sub
Run Method
Descrīption
Runs a file or application.
運行一個文件或應用程序.
Syntax
object.Run file, [params], [dir], [op], [mode]
Argument Descrīption
object A test object of type SystemUtil.
SystemUtil類型的測試對象.
file Required. A String value.
The name of the file you want to run.
必須.一個字符串值.
你想要運行的文件的名稱.
params Optional. A String value.
If the specified file argument is an executable file, use the params argument to specify
any parameters to be passed to the application.
可選.一個字符串值.
如果file參數中指定的是一個可執行文件,則可以使用params參數來指定該可執行文件的運行參數.
dir Optional. A String value.
The default directory of the application or file.
可選.一個字符串值.
應用程序或文件的默認目錄.
op Optional. A String value. The action to be performed. If this argument is blank ( ""), the
open operation is performed.
The following operations can be specified for the op argument:
可選.一個字符串值.將要被執行的動作.如果該參數值為空(""),則默認操作為open操作.
下面是op參數中可以指定的操作:
Operation Descrīption
open
Opens the file specified by the FileName parameter. The file can be an
executable file, a document file, or a folder. Non-executable files are
open in the associated application.
打開file參數中所指定的文件.文件有可能是一個可執行文件,一個文檔文件,或
一個文件夾.非可執行文件會被相應的應用程序打開.
edit
Launches an editor and opens the document for editing. If the FileName
argument does not specify an editable document file, the statement
fails.
將文件在文件編輯器中打開以進行編輯.如果file參數中指定的文件不可編輯,則
本語句失敗.
explore
Explores the folder specified by the FileName argument.
打開由file參數中所指定的文件夾.
find
Initiates a search starting from the specified folder path.
在file參數所指定的文件夾中進行搜索.
print
Prints the document file specified by the FileName argument. If the
specified file is not a printable document file, the statement fails.
打印在file參數中所指定的文檔.如果參數中所指定的文檔不可打印,則語句失敗.
mode Optional. An Integer value.
Specifies how the application is displayed when it opens. You can specify one of the modes
in the table below.
Default = 1
可選.一個Integer值. 指定應用程序打開時的顯示模式.可以指定以下幾種打開模式.默認模式是1.
Mode Descrīption
0
Hides the window and activates another window.
隱藏程序窗口,激活另外一下窗口.
1
Activates and displays the window. If the window is minimized or maximized,
the system restores it to its original size and position. Specify this flag when
displaying the window for the first time.
激活并顯示程序窗口.如果窗口是最大化或最小化狀態,則將它恢復為默認窗口大小并放
置于默認位置.
2
Activates the window and displays it as a minimized window.
激活窗口并最小化.
3
Activates the window and displays it as a maximized window.
激活窗口并最大化.
4
Displays the window in its most recent size and position. The active window
remains active.
按照窗口最近一次的顯示大小及位置顯示該窗口,但不激活該窗口.原來活動的窗口仍保
持活動狀態.
5
Activates the window and displays it in its current size and position.
激活窗口,保持當前的大小及位置不變.
6
Minimizes the specified window and activates the next top-level window in the
Z order.
最小化指定的窗口,并激活它的下一個top-level窗口(按Z順序找到它的下一下top-level
窗口).
7
Displays the window as a minimized window. The active window remains active.
顯示窗口并最小化,但不激活該窗口.原來活動的窗口仍保持活動狀態.
8
Displays the window in its current state. The active window remains active.
顯示窗口,大小及位置保存不變.原來活動的窗口仍保持活動狀態.
9
Activates and displays the window. If the window is minimized or maximized,
the system restores it to its original size and position. Specify this flag when
restoring a minimized window.
激活并顯示窗口.如果窗口處于最大化或最小化狀態,則將它恢復為原始大小與位置.
10
Sets the show-state based on the state of the program that started the
application.
Return Value
None
Remarks
When specifying a non-executable file, the file opens in the associated application.
當指定的是一個非可執行文件時,文件被相應的應用程序打開.
Note: A SystemUtil.Run statement is automatically added to your test when you run an application from the Start menu or the Run dialog box while recording a test.
注意:在錄制腳本的過程中,如果你從系統的"開始"菜單或"運行"對話框中運行應用程序時,SystemUtil.Run語句會自動添加到腳本中.
Tip: You can also use this method to perform operations on the specified file, similar to the usage of the Windows ShellExecute command.
Tip:你也可以使用本方法對指定的文件進行操作,該功能類似于使用Windows ShellExecute命令.
Example
Open a Text File in the Default Text Application (Notepad)
本例使用Run方法打開了一個名為type.txt的文件(txt類型文件的默認打開程序是Notpad),然后向文件中輸入"happy days"文字,然后使用快捷鍵保存該文件,然后關閉NotePad應用程序.
Sub CloseDescendentProcesses_Example()
SystemUtil.Run "C:\type.txt", "", "", ""
Window("Text:=type.txt - Notepad").Type "happy days"
Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUp
Window("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUp
Window("Text:=type.txt - Notepad").Close
End Sub