Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Is there a way to use SilkTest Classic to modify the priority of a running process?

Is there a way to use SilkTest Classic to modify the priority of a running process?

For Windows NT and above, you can use the Processes list in Task Manager to modify the priority of a process. You must highlight the process and right-click it, then select the new priority from the Set Priority pop-up submenu. Fortunately it is straightforward for SilkTest to do this, since SilkTest sees all of the Task Manager objects.

EXAMPLE

You can use the following SetPriority() method to set the priority of any process, including Partner.exe or Agent.exe. Included with the method is a declaration for Task Manager and its pop-up menu. Following the declaration is a simple testcase that illustrates the method. Keep in mind that if you are in a distributed environment, you must set the Agent.exe priority on the target machine but the Partner.exe priority on the host machine.

[+] winclass ProcessPopupMenu : PopupMenu
    [ ] tag "$PopupMenu/({pPopup.x}, {pPopup.y})"
    [+] property pPopup
        [+] POINT Get ()
            [ ] POINT pPopup = {}
            [+] with WindowParent (this)
                [ ] INTEGER iProcess = .GetSelIndex ()
                [ ] RECT rItem = .GetItemRect (iProcess, 1)
            [ ] 
            [ ] return {rItem.xSize / 2, rItem.ySize / 2}
            [ ] 
    [ ] 
    [+] MenuItem EndProcess
        [ ] tag "End Process"
    [+] MenuItem EndProcessTree
        [ ] tag "End Process Tree"
    [+] MenuItem Debug
        [ ] tag "Debug"
    [+] Menu SetPriority
        [ ] tag "Set Priority"
        [+] MenuItem Realtime
            [ ] tag "Realtime"
        [+] MenuItem High
            [ ] tag "High"
        [+] msw2000, mswxp MenuItem AboveNormal
            [ ] tag "AboveNormal"
        [+] MenuItem Normal
            [ ] tag "Normal"
        [+] msw2000, mswxp MenuItem BelowNormal
            [ ] tag "BelowNormal"
        [+] MenuItem Low
            [ ] tag "Low"
[ ] 
[+] window MainWin TaskManager
    [ ] tag "[DialogBox]*Task Manager"
    [ ] 
    [ ] // The working directory of the application when it is invoked
    [ ] const sDir = "C:\"        // can be valid directory, since it is not really used
    [ ] 
    [ ] // The command line used to invoke the application
    [+] property sCmdLine
        [+] STRING Get ()
            [ ] return "{SYS_GetEnv ("SystemRoot")}\System32\taskmgr.exe"
    [ ] 
    [ ] // The first window to appear when the application is invoked
    [ ] // const wStartup = ?
    [ ] 
    [ ] // The list of windows the recovery system is to leave open
    [ ] // const lwLeaveOpen = {?}
    [ ] 
    [+] void SetPriority (STRING sProcess, STRING sPriority)
        [ ] BOOLEAN bAlreadyOpen = TRUE
        [+] if !Exists ()
            [ ] bAlreadyOpen = FALSE
            [ ] Invoke ()
        [ ] 
        [ ] SetActive ()
        [ ] 
        [ ] // Go to Processes list
        [ ] DialogBox1.PageList1.Select ("Processes")
        [ ] 
        [+] with DialogBox1.ListView1
            [ ] // Order processes by name so that the order does not change
            [ ] .Header1.ImageName.Click ()
            [ ] .ListView1.Header1.ImageName.Click ()
            [ ] 
            [ ] .Select ("{sProcess};*")
            [ ] 
            [ ] STRING sOrigBtns
            [+] do
                [ ] sOrigBtns = Agent.SetOption (OPT_MENU_INVOKE_POPUP, "")
                [ ] 
                [ ] .ProcessMenu.SetPriority.MenuItem(sPriority).Pick ()
                [ ] 
                [ ] Agent.SetOption (OPT_MENU_INVOKE_POPUP, sOrigBtns)
            [+] except
                [ ] Agent.SetOption (OPT_MENU_INVOKE_POPUP, sOrigBtns)
                [ ] reraise
        [ ] 
        [ ] // Confirm change
        [+] if MessageBox.Message.Exists () && MatchStr ("*sure you want to change the priority class?", MessageBox.Message.GetText ())
            [ ] MessageBox.SetActive ()
            [ ] MessageBox.Yes.Click ()
        [+] else
            [ ] STRING sMsg = ""
            [+] if MessageBox.Message.Exists ()
                [ ] sMsg = MessageBox.Message.GetText ()
            [ ] RaiseError (1, "Unexpected error message: {sMsg}")
        [ ] 
        [+] if !bAlreadyOpen
            [ ] SetActive ()
            [ ] Close ()
    [ ] 
    [+] Menu File
        [ ] tag "File"
        [+] MenuItem NewTaskRun
            [+] multitag "New Task (Run...)"
                [ ] "$40001"
        [+] MenuItem ExitTaskManager
            [+] multitag "Exit Task Manager"
                [ ] "$40002"
    [+] Menu Options
        [ ] tag "Options"
        [+] MenuItem AlwaysOnTop
            [+] multitag "Always On Top"
                [ ] "$40006"
        [+] MenuItem MinimizeOnUse
            [+] multitag "Minimize On Use"
                [ ] "$40007"
        [+] MenuItem HideWhenMinimized
            [+] multitag "Hide When Minimized"
                [ ] "$40065"
        [+] MenuItem Show16BitTasks
            [+] multitag "Show 16-bit tasks"
                [ ] "$40098"
    [+] Menu View
        [ ] tag "View"
        [+] MenuItem RefreshNow
            [+] multitag "Refresh Now"
                [ ] "$40053"
        [+] Menu UpdateSpeed
            [ ] tag "Update Speed"
            [+] MenuItem High
                [+] multitag "High"
                    [ ] "$40022"
            [+] MenuItem Normal
                [+] multitag "Normal"
                    [ ] "$40023"
            [+] MenuItem Low
                [+] multitag "Low"
                    [ ] "$40024"
            [+] MenuItem Paused
                [+] multitag "Paused"
                    [ ] "$40025"
        [+] MenuItem SelectColumns
            [+] multitag "Select Columns"
                [ ] "$40052"
    [+] Menu Help
        [ ] tag "Help"
        [+] MenuItem TaskManagerHelpTopics
            [+] multitag "Task Manager Help Topics"
                [ ] "$40049"
        [+] MenuItem AboutTaskManager
            [+] multitag "About Task Manager"
                [ ] "$40021"
    [+] DialogBox DialogBox1
        [ ] tag "$0"
        [+] ListView ListView1
            [ ] tag "$1009"
            [+] Header Header1
                [ ] tag "$0"
                [+] PushButton ImageName
                    [ ] tag "Image Name"
                [+] PushButton PID
                    [ ] tag "PID"
                [+] PushButton CPU
                    [ ] tag "CPU"
                [+] PushButton CPUTime
                    [ ] tag "CPU Time"
                [+] PushButton MemUsage
                    [ ] tag "Mem Usage"
            [ ] // Added for pop-up menu
            [ ] ProcessPopupMenu ProcessMenu
        [+] PushButton EndProcess
            [+] multitag "End Process"
                [ ] "$1010"
    [+] PageList PageList1
        [ ] tag "$1000"
    [+] StatusBar StatusBar1
        [ ] tag "$100"
        [+] DynamicText DynamicText1
            [ ] tag "#1"
        [+] DynamicText DynamicText2
            [ ] tag "#2"
        [+] DynamicText DynamicText3
            [ ] tag "#3"
        [+] DynamicText DynamicText4
            [ ] tag "#4"
[+] window MessageBoxClass MessageBox
    [ ] tag "~ActiveApp/[DialogBox]$MessageBox"
    [+] PushButton OK
        [ ] tag "OK"
    [+] PushButton Cancel
        [ ] tag "Cancel"
    [+] PushButton Yes
        [ ] tag "Yes"
    [+] PushButton No
        [ ] tag "No"
    [+] StaticText Message
        [ ] motif tag "#2"
        [ ] tag "#1"
[ ] 
[+] testcase TestSetPriority ()
    [ ] TaskManager.SetPriority ("Partner.exe", "High")
    [ ] TaskManager.SetPriority ("Agent.exe", "High")
    [ ] 
[ ] 

Old KB# 22489

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:32
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.