Jump to content

Auto-Script Pausing

Recommended Posts


So I've been working on an automated web script that interacts with keyword websites, but it uses a virtual machine.  Once a user disconnects from the remote desktop session, the screen goes black and my pixelgetcoord functions all fail, even though the .exe process still runs.  (I don't think there's a solution for that, but I'd be curious to hear any ideas as I've tried several) NBD, I just leave the remote desktop connection window, but if I disconnect or my power goes out (like it just did), the script fails and does funky things.  I came up with a brilliant idea of calling another compiled script (PauseBlack.exe) at the start of the first one (code below) to activate the hotkey.  The PauseBlack script is intended to send the PAUSE key once it detects that the screen has gone black, in theory pausing the main script.  What I'm getting, however, is that the first instance of the send PAUSE doesn't trigger the hotkey, but rather after I click off the msgbox, it will pause the script, presumably using the second instance of Send PAUSE.  I thought the first send would pause the original script, allow the user to click off the MSGbox when they return to the machine, and the script would unpause the initial one to continue, while the PauseBlack continues to check for a black screen.  Any help is appreciated, even a "you have no idea what you're doing, you should be doing it this way" answer.  :)


#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=..\Project Files\Project 1.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <Excel.au3>
#include <IE.au3>
#include <File.au3>
Opt("Wintitlematchmode", 2)

ShellExecute(@DesktopDir & "\AutoIt Files\PauseBlack.exe")

Global $g_bPaused = False
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Func TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        ToolTip('Script is "Paused"', 0, 0)
EndFunc   ;==>TogglePause

Func Terminate()
EndFunc   ;==>Terminate


#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

        $iColor = PixelGetColor(@DesktopWidth - 5, @DesktopHeight - 5)
                $color = Hex($iColor, 6)
                ;MsgBox(0, "Color", $color, 1)
                If $color = "FFFFFF" Then
                    MsgBox(0, "Paused", "Script paused due to disconnection. Click OK to restart")
    Until 4 = 5



Share this post

Link to post
Share on other sites

When connectiom is closed or broken, no interaction with a GUI is possible, there is no GUI you can interact with. Maybe this: http://www.networkautomation.com/urc/knowledgebase/running-interactive-tasks-in-minimized-remote-desktop-windows/4ecdf43e03470/ will help you understanding the possible rdp features.

I think the only possible solution is do not disconnect and buy a uninteruptable power supply to avoid power off.

Edited by AutoBert

Share this post

Link to post
Share on other sites

We have been working on running scripts on a VM as well.  The scripts interact with a Meditech (Hospital Information System) client and scrape and input data.

When the RDP session ends, the script stops working.  I've found that using DameWare Remote Control software seems to work for us.  Disconnecting a DameWare session leaves the user account logged in.  Maybe you could give that a try.

Share this post

Link to post
Share on other sites
On 7/27/2016 at 9:08 PM, singbass said:

I've found that using DameWare Remote Control software seems to work for us.  Disconnecting a DameWare session leaves the user account logged in

Even VNC is a good option. I'm not sure if it supports multiple sessions (you may have to change port numbers). In these cases, much of the problem lies in how you access the machine over the network rather than the script. 

As it is quoted here http://stackoverflow.com/questions/5493200/terminal-session-when-minimized-disconnected-returns-a-blank-screen-upon-capturi

If you minimize the Remote Desktop windon, Windows switches the remote session to the GUI-less mode and does not display windows and controls. As a result, TestComplete (or TestExecute) will be unable to interact with the tested application’s GUI, as it does not exist and your automated GUI test will fail. To work around the issue, you can change the Remote Desktop’s registry settings on your local computer (where you launch the Remote Desktop): On your local computer, close all open Remote Desktop sessions. Launch the Registry editor (regedit.exe). Navigate to one of the following Registry keys, depending on whether you wish to modify the Remote Desktop settings only for the current user or for all users on the computer:


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now