site
stats
By Anish Pillai Anish Pillai Posted under QTP Basic Stuff | QTP Concepts

Understanding SystemUtil.Run syntax with examples

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

SystemUtil.Run is an inbuilt QTP command that lets you run a file or an application. Mostly SystemUtil.Run command is used to open browser with a specific URL. But there is much more that can be done with it. Here in this article, you’ll see various examples on how to use SystemUtil.Run for different purposes. Let’s first go through the syntax of SystemUtil.Run method –

SystemUtil.Run file, [params], [dir], [op], [mode]

Argument Description
file String Value [Mandatory]. The name of the file you want to run.
params String Value [Optional]. If the specified file argument is an executable file, use the params argument to specify any parameters to be passed to the application.
dir String Value [Optional]. The default directory of the application or file.
op String Value [Optional]. The action to be performed – open, edit, explore, find & print.If this argument is blank (“”), the open operation is performed.

Operation Description
open Opens the file specified by the file parameter. The file can be an executable file, a document file, or a folder. Non-executable files are open in the associated application.
edit Launches an editor and opens the document for editing. If the file argument does not specify an editable document file, the statement fails.
explore Explores the folder specified by the file argument.
find Initiates a search starting from the specified folder path.
print Prints the document file specified by the file argument. If the specified file is not a printable document file, the statement fails.
mode Integer Value [Optional]. Specifies how the application is displayed when it opens. Default : 1

Mode Description
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.
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.

Examples : SystemUtil.Run

1. Using file argument:

SystemUtil.Run "iexplore.exe" 'opens internet explorer with default page
SystemUtil.Run "notepad.exe" 'opens blank notepad window
SystemUtil.Run "notepad" 'opens blank notepad window
SystemUtil.Run "D:\AutomationRepository.txt" 'since this is a non executable file, the file opens in the associated application i.e. notepad in this case

2. Using params argument

'If 'file' argument is an executable file, then 'params' can be used to specify the arguments to the application
SystemUtil.Run "iexplore.exe", "http://www.automationrepository.com" 'opens Automation Repository in Internet Explorer browser
SystemUtil.Run "notepad.exe", "D:\SomeTextFile.txt" 'opens the text file in notepad

3. Using dir argument

'dir argument can be used to specify the default location of the application
SystemUtil.Run "iexplore.exe", "", "C:\Program Files\Internet Explorer\"

4. Using op argument

SystemUtil.Run "notepad.exe", "D:\AutomationRepository.txt", "", "open" 'open a file
SystemUtil.Run "D:\AutomationRepository.txt", "", "", "edit" 'open file in edit mode
'Explore the folder specified by 'file' argument. Refer figure-1
SystemUtil.Run "My Computer", "", "", "explore"
'Initiate a search starting from the specified folder path. Refer figure-2
SystemUtil.Run "D:\", "", "", "find"
SystemUtil.Run "D:\AutomationRepository.txt", "", "", "print" 'prints a document specified by 'file' argument

5.Using mode argument

SystemUtil.Run "notepad.exe", "D:\AutomationRepository.txt", "", "", 0 'the file is opened in hidden mode
SystemUtil.Run "notepad.exe", "D:\AutomationRepository.txt", "", "", 1 'activates and displays the window
SystemUtil.Run "notepad.exe", "D:\AutomationRepository.txt", "", "", 2 'opens the window in minimized state
Explore Folder

figure-1

Find Window

figure-2

If you liked this article, you can join our blog to get free email updates directly in your inbox.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
  • josha

    i want to compare two files

    • Anish10110

      Josha,

      Can you provide bit more information about the query?

      • josha

        Anish,
        I have two files.i take content from document 2 and compare it in document1.

        • Anish10110

          Josha, What type of files are these? txt, word doc or something else? Based upon the type of files you might be able to write code in VBScript to compare them.

  • josha

    It's notepad file.

    • Anish10110

      Emailed You..

  • Henrik Nor

    Hi Anish, I dont know if this forum is still open, but I am looking for a soltion to add the content from an Excel cell in sted of a string: ""

    Like this:
    SystemUtil.Run "iexplore.exe", "http://www.automationrepository.com"

    Where SystemUtil.Run "iexplore.exe", "http://www.automationrepository.com" is substituted by my Excel reference: objSheet.cells(row,2)

    Do you know how I can make this work?

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×