Jump to content

only one program will run inside if then


leo8888
 Share

Recommended Posts

When you are manually starting QBWC.exe, are you starting it from a shortcut ?  Are you sure that the working directory is the same and there is no parameters ? Does it require admin rights, or run x64 ?  Verify every single details, cause I never seen a situation where a AutoIt run was defective...

Link to comment
Share on other sites

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

9 minutes ago, leo8888 said:

The web connector we use now was supplied by another vendor, service titan. I may ask them if there is a log file being generated somewhere under a different name.

Just look in the servicetitan dirs and below for a file that just got updated.

odds are it says why the process is terminating on its own the second time.

Code hard, but don’t hard code...

Link to comment
Share on other sites

16 minutes ago, Nine said:

When you are manually starting QBWC.exe, are you starting it from a shortcut ?  Are you sure that the working directory is the same and there is no parameters ? Does it require admin rights, or run x64 ?  Verify every single details, cause I never seen a situation where a AutoIt run was defective...

As suggested by Jocko I searched for any files being updated in the service titan directory but there are none. When the web connector is running is has it's own log window but I cannot find a log of it outside of that.

The shortcut has the same working directory as the program and I verified in task manager that the qbwc.exe is 32bit.

I am testing from the console logged in as administrator.

As a test I tried just putting the run line by itself in a separate script and if I break out of the first script and run the second the qbwc.exe will start.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=WebConnectorResetMonitor.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>

      Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe") ; Restart the Service Titan Web Connector

 

Link to comment
Share on other sites

If the shortcut has a working directory, I would suggest you add it to the run statement just for safety.  Copy the shortcut working directory directly into the run statement.

Link to comment
Share on other sites

3 minutes ago, Nine said:

If the shortcut has a working directory, I would suggest you add it to the run statement just for safety.  Copy the shortcut working directory directly into the run statement.

Sorry, I forgot to mention that I added that to the code already:

$iPID = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe", "C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC")

 

Link to comment
Share on other sites

Can you create a .bat file that would launch QBWC.exe ?  If that is working, you could Run the batch file instead.  Maybe you need to end the working directory with a \ since there is a space close to the end.

Link to comment
Share on other sites

2 hours ago, Nine said:

Can you create a .bat file that would launch QBWC.exe ?  If that is working, you could Run the batch file instead.  Maybe you need to end the working directory with a \ since there is a space close to the end.

I must have read your thoughts because I already tried that. The batch works fine but when I call it from the script I get the same result as every other command I have tried to run it.

I am beginning to wonder if the OS is somehow blocking the execution. Maybe DEP is coming into play. I would have to disable it and reboot the server to test.

Link to comment
Share on other sites

Here’s the manual on the SDK for the connector, it’s possibly what servicetitan used to create their integration.

https://static.developer.intuit.com/qbSDK-current/doc/pdf/QBWC_proguide.pdf

Didn’t see too much that looked helpful, though logging can be turned off and on, assuming the systray options are present:

FD9BAC9C-C8AF-46B6-A7CE-CCB65C159BC9.thumb.png.9a0fe65a51791f548207a6a78802328a.png

Code hard, but don’t hard code...

Link to comment
Share on other sites

41 minutes ago, JockoDundee said:

Here’s the manual on the SDK for the connector, it’s possibly what servicetitan used to create their integration.

https://static.developer.intuit.com/qbSDK-current/doc/pdf/QBWC_proguide.pdf

Didn’t see too much that looked helpful, though logging can be turned off and on, assuming the systray options are present:

FD9BAC9C-C8AF-46B6-A7CE-CCB65C159BC9.thumb.png.9a0fe65a51791f548207a6a78802328a.png

Thank you Jocko.

The option to turn logging on or off are not present when I right click the connector on the systray. Service Titan may have removed that option I am guessing.

I even tried a ridiculously long wait delay of 6 minutes before the script restarted the connector but it still did not work. Strange thing is I can still manually restart it immediately from outside the script.

Link to comment
Share on other sites

11 minutes ago, leo8888 said:

The option to turn logging on or off are not present when I right click the connector on the systray. Service Titan may have removed that option I am guessing.

Normally I wouldn’t even suggest this but have you tried just having autoit give you a command window instead of running qbwc ?

Then you could run it from the command window yourself, if it were to fail it might indicate that it’s the shell environment that’s the problem, then you could maybe figure out what is different.

Code hard, but don’t hard code...

Link to comment
Share on other sites

So I have verified that AutoIT is definitely not the issue. I created a simple batch to kill and restart the qbwc.exe and it also only works as a "toggle".

If I run it the first time it will kill the web connector but not restart it. The second time it will restart the connector.

It seems the OS is not allowing one single process to kill and restart the qbwc.exe.

I wanted to thank everyone for their time and suggestions!

@echo off
TaskKill /IM qbwc.exe /T /F
pause 
start C:\"Program Files (x86)"\ServiceTitan\"ServiceTitan QBWC"\QBWC.exe

 

Link to comment
Share on other sites

Have you tried adding a second run after the first spaced by a few secs ?  Would that works ?  Or even better a Do...Until ProcessExist ("QBWC.exe")  with a Sleep?

Link to comment
Share on other sites

6 minutes ago, Nine said:

Have you tried adding a second run after the first spaced by a few secs ?  Would that works ?  Or even better a Do...Until ProcessExist ("QBWC.exe")  with a Sleep?

Yes, I was trying that last week before I left work. The Script would just hang indefinitely waiting for the process to start, even with a very long sleep (over 5 minutes) or multiple start lines separated by sleeps. I watched task manager and would sometimes see the qbwc.exe process start for a split second but disappear.

Link to comment
Share on other sites

Hey,

Just wondering if this is a legitimate syntax having double quotes like this?

18 minutes ago, leo8888 said:

start C:\"Program Files (x86)"\ServiceTitan\"ServiceTitan QBWC"\QBWC.exe

Is this the same line that starts it in the 2nd run?

I would try as

start "C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe"

also with two double-quotes after start. Remember reading something like a window title is needed, even though it may be an empty string.

start "" "C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe"

Link to comment
Share on other sites

Ok, maybe launch a second process with :

Run(@AutoItExe & ' /AutoIt3ExecuteLine "Run(''C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe'',''C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\'')"')

After it was killed successfully by the first. :sweating:

Link to comment
Share on other sites

4 minutes ago, GokAy said:

Hey,

Just wondering if this is a legitimate syntax having double quotes like this?

Is this the same line that starts it in the 2nd run?

I would try as

start "C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe"

also with two double-quotes after start. Remember reading something like a window title is needed, even though it may be an empty string.

start "" "C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe"

Yes, I can use that from a command prompt and the batch file with always start it on the second run but not the first.

Link to comment
Share on other sites

5 minutes ago, Nine said:

Ok, maybe launch a second process with :

Run(@AutoItExe & ' /AutoIt3ExecuteLine "Run(''C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe'',''C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\'')"')

After it was killed successfully by the first. :sweating:

I like this idea. I'll give it a try. Thank you.

Link to comment
Share on other sites

56 minutes ago, Nine said:

Ok, maybe launch a second process with :

Run(@AutoItExe & ' /AutoIt3ExecuteLine "Run(''C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe'',''C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\'')"')

After it was killed successfully by the first. :sweating:

Tried to cleanup and shorten the code and implement the suggestion:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=WebConnectorResetMonitor.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <Constants.au3>
#include <Array.au3>

Opt ("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

local $MainGui = GuiCreate("Quickbooks Web Connector Reset Monitor",450,150)
GUISetOnEvent($GUI_EVENT_CLOSE, "CancelButton")
local $iCancelButton = GuiCtrlCreateButton("End Monitor",150,50,100,25)
local $iLastReset = GUICtrlCreateLabel ( "Waiting for reset request...", 50, 100, 400, 25)
local $iResetCount = 0
GUICtrlSetFont(-1, 12)
GUICtrlSetOnEvent($iCancelButton, "CancelButton")
GUISetState(@SW_SHOW, $MainGui)
local $iRet = 0

While 1
    Sleep(100) ; Sleep to reduce CPU usage
    If FileExists("e:\QuickBooks\ResetWebConnector.txt") Then   ; Check for trigger file
      $iRet = Run("TaskKill /IM qbwc.exe /T /F")
      ConsoleWrite("TaskKill " & $iRet & "/" & @error & @CRLF)
      $iRet = ProcessWaitClose("qbwc.exe")
      ConsoleWrite("WaitClose " & $iRet & "/" & @error & @CRLF)
      $iRet = Run(@AutoItExe & ' /AutoIt3ExecuteLine "Run(''C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe'',''C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\'')"')
      ConsoleWrite("AutoIT Run " & $iRet & "/" & @error & @CRLF)
      $iResetCount = $iResetCount + 1
      GUICtrlSetData($iLastReset, "Last Reset: " & _Now() & "  Count: " & $iResetCount)
      FileDelete("e:\QuickBooks\ResetWebConnector.txt")   ; Delete trigger file
      Sleep(2000)
  EndIf
WEnd

Func CancelButton()
  Exit
EndFunc   ;==>CancelButton

GuiDelete($MainGui)

 

>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Administrator\Desktop\Command Scripts\WebConnectorResetBak2.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
TaskKill 20824/0
WaitClose 1/0
AutoIT Run 24904/0

 

Still the same result. Everything SHOULD work but the process just will not restart. If I run the single command to start the process in a different script it works fine.

 

Link to comment
Share on other sites

After trying many different combinations of script commands and batch file commands I decided to take a new approach. I believe that the operating system (Server 2012 R2) is blocking the restart through DEP, at least that is my guess, and I did not want to have to disable DEP since everything else is working fine.

Since the connector seemed like it would always restart on the second try if I used a separate script or batch file I decided to create two separate scripts. One to kill the connector and one to restart it.

Then I changed the code on the workstations script to send the trigger files to both scripts, pause 20 seconds, then send the trigger file to just the restart script. I have tested several times from a workstation and it appears to work fine.

Here are the updated scripts I came up with. They are messy but they work.

Thank you all for your suggestions and ideas!

Script to monitor for kill command:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=WebConnectorResetMonitor.exe
#AutoIt3Wrapper_Outfile_x64=WebConnectorResetMonitor64.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <Constants.au3>
#include <Array.au3>

Opt ("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

local $MainGui = GuiCreate("Quickbooks Web Connector Reset Monitor",450,150)
GUISetOnEvent($GUI_EVENT_CLOSE, "CancelButton")
local $iCancelButton = GuiCtrlCreateButton("End Monitor",150,50,100,25)
local $iLastReset = GUICtrlCreateLabel ( "Waiting for reset request...", 50, 100, 400, 25)
local $iResetCount = 0
GUICtrlSetFont(-1, 12)
GUICtrlSetOnEvent($iCancelButton, "CancelButton")
GUISetState(@SW_SHOW, $MainGui)
local $iRet = 0

While 1
    Sleep(100) ; Sleep to reduce CPU usage
    If FileExists("e:\QuickBooks\ResetWebConnector.txt") Then   ; Check for trigger file
      $iRet = Run("TaskKill /IM qbwc.exe /T /F")
      ConsoleWrite("TaskKill " & $iRet & "/" & @error & @CRLF)
      $iRet = ProcessWaitClose("qbwc.exe")
      ConsoleWrite("WaitClose " & $iRet & "/" & @error & @CRLF)
      $iResetCount = $iResetCount + 1
      GUICtrlSetData( $iLastReset, "Last Reset: " & _Now() & "  Count: " & $iResetCount )
      FileDelete("e:\QuickBooks\ResetWebConnector.txt") ; Delete trigger file
    EndIf
WEnd

Func CancelButton()
  Exit
EndFunc   ;==>CancelButton

GuiDelete($MainGui)

 

Script to monitor for restart command:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=WebConnectorRestartMonitor.exe
#AutoIt3Wrapper_Outfile_x64=WebConnectorRestartMonitor64.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <Constants.au3>

Opt ("MustDeclareVars", 1)

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

local $MainGui = GuiCreate("Quickbooks Web Connector Restart Monitor",450,150)
GUISetOnEvent($GUI_EVENT_CLOSE, "CancelButton")
local $iCancelButton = GuiCtrlCreateButton("End Monitor",150,50,100,25)
local $iLastRestart = GUICtrlCreateLabel ( "Waiting for restart request...", 50, 100, 400, 25)
GUICtrlSetFont(-1, 12)
GUICtrlSetOnEvent($iCancelButton, "CancelButton")
GUISetState(@SW_SHOW, $MainGui)
local $iRet = 0

While 1
    Sleep(100) ; Sleep to reduce CPU usage
    If FileExists("e:\QuickBooks\RestartWebConnector.txt") Then ; Check for trigger file
      Sleep(5000)
      $iRet = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe", "C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\")
      ConsoleWrite("Restart " & $iRet & "/" & @error & @CRLF)
      GUICtrlSetData( $iLastRestart, "Last Restart: " & _Now() )
      FileDelete("e:\QuickBooks\RestartWebConnector.txt") ; Delete trigger file
    EndIf
WEnd

Func CancelButton()
  Exit
EndFunc   ;==>CancelButton

GuiDelete($MainGui)

 

Workstation script to send kill and reset trigger files to server:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Reset Web Connector.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

local $MainGui = GuiCreate("Reset Quickbooks Web Connector on PRS4",450,150)
GUISetOnEvent($GUI_EVENT_CLOSE, "CancelButton")
local $iResetButton = GuiCtrlCreateButton("Reset Connector",80,50,140,25)
GUICtrlSetFont(-1, 12)
GUICtrlSetOnEvent($iResetButton, "ResetButton")
local $iCancelButton = GuiCtrlCreateButton("Cancel",275,50,80,25)
GUICtrlSetFont(-1, 12)
GUICtrlSetOnEvent($iCancelButton, "CancelButton")
local $iResetWait = GUICtrlCreateLabel ( "Waiting for reset request...", 50, 100, 400, 25)
GUISetState(@SW_SHOW, $MainGui)

While 1
    Sleep(100) ; Sleep to reduce CPU usage
WEnd

Func ResetButton()
  $tCur = _Date_Time_GetSystemTime()
  GUICtrlSetData( $iResetWait, "Resetting Web Connector, Please Wait... " )
  ShellExecuteWait("cmd.exe", "/c echo $tCur > i:\ResetWebConnector.txt")
  ShellExecuteWait("cmd.exe", "/c echo $tCur > i:\RestartWebConnector.txt")
  Sleep(20000)
  ShellExecuteWait("cmd.exe", "/c echo $tCur > i:\RestartWebConnector.txt")
  Exit
EndFunc   ;==>ResetButton

Func CancelButton()
  Exit
EndFunc   ;==>CancelButton

GuiDelete($MainGui)

 

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...