Jump to content

Recommended Posts

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 Function
Func Main()
    ; check if program already running

    If WinExists("[TITLE:"&$title&"]") Then
        ;program running close it and wait 5 seconds for it close

; 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
        ; wait 10 seconds incase it takes a while to launch
        Sleep (10000)
        ; Select the window to execute the remianing commands
        ; send keys to start Scan
    Else ; if program not found, message box saying not found
        MsgBox($MB_SYSTEMMODAL,"Error","Program " & $qbDSM & " not found")


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


Edited by Jos
Link to post
Share on other sites

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


Example Debug functions:

Global Const $sLog = @ScriptDir & "\log.txt"

Debug("Before calling Run!")
If ErrMsg("Run Failed :o") Then Exit

Func Debug($sMsg, $sPrefix = "+")
    ; I always forget to add a newline when using ConsoleWrite, so my debug function adds it
    ; The plus makes stuff green in SciTE... it's a good color
    ConsoleWrite($sPrefix & " " & $sMsg & @CRLF)
    ; Write everything to the log
    FileWrite($sLog, $sMsg)

; Call this function with just a message, everything else is filled out for you
; Returns the error, meaning you can use it in an If to check if the function failed
Func ErrMsg($sMsg, $iError = @error, $iExtended = @extended, $iScriptLine = @ScriptLineNumber)
    ; Print if there is an error, but use ! which makes SciTE red, looks like an error too
    If @error Then
        Debug("Error: " & $iError & " Extended: " & $iExtended & " " & $sMsg, "!")
        If Not @Compiled Then Debug("Failed on line: " & $iScriptLine, ">")
    ; Keep the Error values
    SetError($iError, $iExtended, $iError)

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


My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Link to post
Share on other sites

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.

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

    No registered users viewing this page.

  • Create New...