Main window commands are responsible for interacting with the primary window of an application, or the application itself rather than the current child window.
The BringToForeground
command is used to bring the main application into the foreground and to trigger a Windows “new foreground window” event which, in turn, will trigger any relevant pending WhenWindow
commands in the desktop script.
This is necessary when an application opens behind the browser window when starting it from the Vault.
It is also commonly required when interacting with browser-based apps such as Flash sites or those that use custom embedded browsers.
When writing scripts, it is recommended to start with the least intrusive option and only move on to the more intrusive ones if necessary. The options are shown below from least visually intrusive to most intrusive.
Option Name | Impact | Technical Notes |
---|---|---|
| Visually low, performance fast | Uses “SwitchToWindow” method. Default timeout is 10000 |
| Visually low, performance mediuim | Uses Cross Process Thread Linking method. Default timeout is 10000 |
| Visually medium, performance medium | Uses programmatic ALT TAB to switch away and back to the window. Often fails to restore window, but does take it away from foreground, can then use Switch option to bring back. Default timeout is 0 |
| Visually high, performance medium | Forces window to minimise and restore. Default timeout is 10000 |
| Visually high, performance medium | Sends the Windows messages SC_HOTKEY and SC_RESTORE to attempt to redraw the window in the foreground. Rarely achieves the aim. Default timeout is 10000 |
The timeout parameter tells the command how many milliseconds to wait while trying to detect that the window is now in the foreground. If the timeout expires then the script moves to the next command. When running multiple BringToForeground
commands in a row it can be beneficial to reduce the default timeout.
BringToForeground BtfAltTab
Microsoft deliberately makes this a difficult task to accomplish programmatically (the reason being to stop malicious software from hijacking a desktop). The result of this is that there are several different ways to try and achieve this effect and some have a more noticeable effect to the users than others.
Use the suggested approach, below, first and then experiment with various combinations of options if that does not work.
Note
It may not be 100% possible to force a window to the foreground because of this designed in behaviour by Windows.
Hint
Experimentation has shown the most effective way to use this command is to use it twice: first with the BtfAltTab
option to ensure the app has been removed from the foreground and then with the BtfSwitch
option to bring it back to the foreground.
BringToForeground BtfAltTab
BringToForeground BtfSwitch
Ensures that any changes made to the bookmark attributes are written back to the My1Login repository.
This must be called after a bmNewPassword
reference in order to save the new password value in the desktop app’s bookmark.
See the Password Change Example
None
SaveChanges
Selects a control on the script process’ forground window, based upon the provided ControlSelectOptions
.
The selected control is the automatic target when the commands below occur after the SelectControl
command:
Used to determine which control in the current window should be selected.
See ControlSelectOptions for details.
// Select the button with Control ID 0x82B3
SelectControl ControlButton 0x82B3
// Select the button ending with the text "SAP"
SelectControl ControlButton EndsWith "SAP"
De-selects any currently selected control.
Any subsequent actions that would target the control will now target the application’s current foreground window.
See SelectControl for details on affected commands.
None
UnSelect
The Wait
command pauses the script execution for one second or for a user specified number of milliseconds.
Warning
Wait
commands should be used sparingly because they give an opportunity for a different app to take over the desktop. It is best to control script execution deterministically if possible.
Parameter Name | Description |
---|---|
timeoutMillisecond | The number of milliseconds that the script should pause for. Default is 1000. |
// Wait for half a second
Wait 500
// Wait for a second (two options)
Wait
Wait 1000
Wait
is typically used to give the user interface time to paint its controls prior to injecting credentials into them. Try without using a Wait
and only add one if nothing appears to be happening when the SendKeys
command (or one of the select commands) is executed.
In most cases a wait of 100ms is adequate and minimises the time when another app could take the screen.