Jump to content

Recommended Posts

Posted (edited)

Hi, We have created a script on our 2019 Server. It works perfectly everytime I run it. I moved the file to a 2008 R2 server and nothing happens at all. I launch the .au3 file and nothing happens. I then moved the file onto a 2016 Server and was able to manually run the file once and then it wouldn't run again. I created a task in task schedular to launch Autoit3.exe and grab the .au3 file upon logon. This works everytime but I still cannot manually run this. Below is our script. 

; AutoIt v3.3.14.5
; https://www.autoitscript.com
#include <MsgBoxConstants.au3>

; Path to QuickBooks Database Server Manager
Global Const $qbDSM = "C:\Program Files (x86)\Common Files\Intuit\QuickBooks\QBServerUtilityMgr.exe"
; Title of window
Global Const $title = "QuickBooks Database Server Manager";

Main()

; Main Function
Func Main()
    ; check if program already running


    If WinExists("[TITLE:"&$title&"]") Then
        ;program running close it and wait 5 seconds for it close
        WinClose("[TITLE:"&$title&"]")
        WinWaitClose("[TITLE:"&$title&"]",5)
    EndIf
    Launch()
EndFunc

; launch the QuickBooks Database Server Manager
Func Launch()

    ; Check if the Program File Exists
    Local $exist = FileExists($qbDSM)

    If $exist Then ; if it does exist
        ; launch the program
        Local $iPID = Run($qbDSM)
        ; wait upto 5 seconds for the window to appear
        WinWait("[TITLE:"&$title&"]","",5)
        ; wait 10 seconds incase it takes a while to launch
        Sleep (10000)
        ; Select the window to execute the remianing commands
        WinActivate($title)
        ; send keys to start Scan
        Scan()
    Else ; if program not found, message box saying not found
        MsgBox($MB_SYSTEMMODAL,"Error","Program " & $qbDSM & " not found")
    EndIf

EndFunc

Func Scan()
    ; send the tab key to move to [Start Scan] button
    Send("{TAB}")
    ; send the enter key to start the scan
    Send("{ENTER}")
    ; send the enter key to close the warning message
    Send("{ENTER}")
    ; wait 15 seconds for the scan to finish
    Sleep (15000)
    ; Lock the screen for security reasons
    ShellExecute("rundll32.exe", "user32.dll,LockWorkStation")
EndFunc

 

Edited by Jos
Posted

When you post code, please use the <> button to insert code :)

I'd suggest a couple things:

1. Check the @error value and/or the return value after calling functions (See the help file for examples) This especially applies to Run, it sets @error
2. Write to the console, it's there for a reason. If you aren't at the server when you run the script, use a custom function (see below) to write to the console AND write to a log
3. Just because you use WinActivate, doesn't mean it is immediately the active window. It may take the window a second or two to be active... see WinWaitActive
4. Consider using Control* functions (ControlSetText, ControlClick, etc) instead of Send. Send should generally be used as a last resort

  Reveal hidden contents

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

  Reveal hidden contents
Posted

If all you are using AutoIT3 for is to Launch the Database Server Manager, why not just slot it in as a delayed schedule start in the Windows Service Queue, and let Windows take care of it?

I think there is already an UDF for setting this up for you.

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
  • Recently Browsing   0 members

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