Jump to content

Script won't when desktop is active


daashag
 Share

Recommended Posts

I made this simple little script to automate a backup. The only problem is it won't run under task scheduler. When I run it under task scheduler it just opens the program than stalls because the window isn't in focus. It will run fine under task scheduler if I am viewing the desktop. For instance If I am remote desktop in and have my remote desktop window is active or maximized it runs fine, If I minimize my remote desktop window it will just hang on the first window, as soon as I click any where on that window It runs. I have tried Send, ControlSend, WinActivate, ControlFocus nothing seems to work. Here is my original code

;Script to Automate Exact backup

;Declare Variables
$cpdst = 'x:\ExactGlobe\ftpbackup\'
;MsgBox(0, "Example", "My variable is " & $bkupsrc)

;Delete files in current directory
FileDelete($cpdst)

;Run Exact 
Run("C:\Program Files\Exact Software\bin\e4shell.exe")


<--------------    This the code I am having problem with.  ------------------------->

; Cancel opening company
WinWait("Open company","") 
If Not WinActive("Open company","") Then WinActivate("Open company","")
WinWaitActive("Open company", "")
ControlSend("Open company", "&Cancel", 5, "!c" ,"")

<------------------------------------------------------------------------------------------->

;Open Menu
WinWaitActive("Exact Globe 2003 Enterprise", "")
Send("!f")

Any help would be appreciated. Thanks

daas

Link to comment
Share on other sites

1st, you need to have permission (username and password) for task scheduler to interact with desktop so hopefully you have that set right.

It looks like you want to click a cancel button but you are using ControlSend. I would use ControlClick to do it. You do not need WinActivate...WinWaitActive for Control* functions

Try this

;Script to Automate Exact backup

;Declare Variables
$cpdst = 'x:\ExactGlobe\ftpbackup\'
;MsgBox(0, "Example", "My variable is " & $bkupsrc)

;Delete files in current directory
FileDelete($cpdst)

;Run Exact
Run('"' & @ProgramFilesDir & '\Exact Software\bin\e4shell.exe"')

; Cancel opening company
WinWait("Open company")
ControlClick("Open company", "&Cancel", 5)

;Open Menu
WinWait("Exact Globe 2003 Enterprise")
If Not WinActive("Exact Globe 2003 Enterprise") Then
    WinActivate("Exact Globe 2003 Enterprise")
EndIf
WinWaitActive("Exact Globe 2003 Enterprise")
Send("!f")

;)

Link to comment
Share on other sites

Appreciate your reply.

I have adminstrator access on the box so that isn't an issue.

I don't think the Exact program uses MS controls. It doesn't work even if I run it manually. I tried your code on some different applications and it worked like a charm. Seems like the only way I can manipulate the Exact program is through keyboard and mouse controls which I can't use because the desktop is not active. Is there any other way? Thanks

;) dass

Link to comment
Share on other sites

So, your desktop is not active but you believe you need keyboard and mouse. Try ControlSend for both to eliminate needing active windows and see if it works.

;Script to Automate Exact backup

;Declare Variables
$cpdst = 'x:\ExactGlobe\ftpbackup\'
;MsgBox(0, "Example", "My variable is " & $bkupsrc)

;Delete files in current directory
FileDelete($cpdst)

;Run Exact
Run('"' & @ProgramFilesDir & '\Exact Software\bin\e4shell.exe"')

; Cancel opening company
WinWait("Open company")
ControlSend("Open company", "", "", "!c")

;Open Menu
WinWait("Exact Globe 2003 Enterprise")
ControlSend("Exact Globe 2003 Enterprise", "", "", "!f")
Link to comment
Share on other sites

So, your desktop is not active but you believe you need keyboard and mouse. Try ControlSend for both to eliminate needing active windows and see if it works.

I believe I need to be able to send keyboard commands to Exact in order for it to go through the different the windows. Which I don't know if I can do if the desktop is not active. I am not talking about sending control commands just straight keyboard commands.

To tell you the truth I have no Idea what the problem is. All I know is when I am not viewing the the desktop the script does not run. Like I said I tried your code on a different application the autoit install.exe, as a matter of fact. Running it as a schedule task it opened the program and went through a series of control clicks with no problems. I tried ControlSend and that does not work either. When I run the following code all I get is a window saying "ok"

; Cancel opening company
WinWait("Open company")
ControlSend("Open company", "&Cancel", 5, "!c")
$var = ControlGetText("Open company", "&Cancel", "5")
 MsgBox(0, "Example", "My variable is " & $var)

Thanks again.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...