Jump to content

only one program will run inside if then


leo8888
 Share

Recommended Posts

Updated code and output from ConsoleWrite.

Code:

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

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
      Local $iRet = Run ("TaskKill /IM qbwc.exe /F")
      ProcessWaitClose("qbwc.exe")
      ConsoleWrite ($iRet & "/" & @error & @CRLF)
      ;MsgBox($MB_SYSTEMMODAL, "Restarting Web Connector", "The Web Connector will restart in 5 seconds or click OK to start it now.", 5)
      ;ShellExecute("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe") ; Restart the QuickBooks Web Connector
      Local $iRet = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe")
      ConsoleWrite ($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)

ConsoleWrite output:

Quote

+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
22400/0
19824/0

 

Link to comment
Share on other sites

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

may be the process "qbwc.exe" spawn some child process so try using the "/T" switch with "taskkill" ,try this code :-
 

While 1
    Sleep(100) ; Sleep to reduce CPU usage
    If FileExists("e:\QuickBooks\ResetWebConnector.txt") Then ; Check for trigger file
      Local $iRet = Run ("TaskKill /IM qbwc.exe /T /F")
      ProcessWaitClose($iRet)
      ConsoleWrite ("closing process : "&$iRet & " / Error : " & @error & @CRLF)
      ;MsgBox($MB_SYSTEMMODAL, "Restarting Web Connector", "The Web Connector will restart in 5 seconds or click OK to start it now.", 5)
      ;ShellExecute("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe") ; Restart the QuickBooks Web Connector
      Local $iRet = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe")
      ConsoleWrite ("starting process : "&$iRet & " / Error : " & @error & @CRLF)
      $iResetCount = $iResetCount + 1
      GUICtrlSetData( $iLastReset, "Last Reset: " & _Now() & "  Count: " & $iResetCount )
      FileDelete("e:\QuickBooks\ResetWebConnector.txt") ; Delete trigger file
    EndIf
WEnd

 

Link to comment
Share on other sites

Thank you.  Seems to be working.  You got both PID correctly without @error.   I made some changes to ensure to get all info.

#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 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, $iPID

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 /F")
    ConsoleWrite("TaskKill " & $iRet & "/" & @error & @CRLF)
    $iRet = ProcessWaitClose("qbwc.exe")
    ConsoleWrite("WaitClose " & $iRet & "/" & @error & @CRLF)
    $iPID = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe")
    ConsoleWrite("Run " & $iPID & "/" & @error & @CRLF)
    $iRet = ProcessWait($iPID)
    ConsoleWrite("Wait " & $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

So after that first attempt, go into Task Manager, you should see the process QBWC.exe

 

Link to comment
Share on other sites

1 minute ago, Nine said:

Thank you.  Seems to be working.  You got both PID correctly without @error.   I made some changes to ensure to get all info.

#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 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, $iPID

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 /F")
    ConsoleWrite("TaskKill " & $iRet & "/" & @error & @CRLF)
    $iRet = ProcessWaitClose("qbwc.exe")
    ConsoleWrite("WaitClose " & $iRet & "/" & @error & @CRLF)
    $iPID = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe")
    ConsoleWrite("Run " & $iPID & "/" & @error & @CRLF)
    $iRet = ProcessWait($iPID)
    ConsoleWrite("Wait " & $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

So after that first attempt, go into Task Manager, you should see the process QBWC.exe

 

That is the strange thing. There seems to be no errors but the qbwc.exe process does not start. I already checked task manager and their are no instances of it running.

I will add the changes and also add the "/T" to taskkill as suggested by Network_Guy.

Link to comment
Share on other sites

Updated code and ConsoleWrite output. The qbwc.exe process still does not start and does not appear in task manager. I also tried checking Windows event logs but do not see anything helpful.

If I leave the script running and manually start the qbwc.exe from the start menu shortcut it will start. The start menu shortcut has the same exact path that I used in the script.

Just want to add that this server does not have any antivirus program running that could be blocking the process.

 

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

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
local $iPID = 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)
    $iPID = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe")
    ConsoleWrite("Run " & $iPID & "/" & @error & @CRLF)
    $iRet = ProcessWait($iPID)
    ConsoleWrite("Wait " & $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)

 

ConsoleWrite output:

TaskKill 17076/0
WaitClose 1/0
Run 22116/0
Wait 22116/0

 

Link to comment
Share on other sites

Wanted to add that with all the suggested changes the script is not behaving as it was when I originally posted it. Now even after dropping the trigger file into the directory a second time the qbwc.exe process will not start.

Before the changes it would always start the second time I dropped the file. Very strange behavior....

Link to comment
Share on other sites

change processwaitclose("qbwc.exe") to  processwaitclose($iRet) with killprocess /T 

cause if qbwc spwan child process , with  processwaitclose("qbwc.exe") u wait for the parent exe only ,but using processwaitclose($iRet) u will wait for parent and child process to close

 

Edited by Network_Guy
Link to comment
Share on other sites

5 minutes ago, Network_Guy said:

change winwaitclose("qbwc.exe") to  winwaitclose($iRet) with killprocess /T 

cause if qbwc spwan child process , with  winwaitclose("qbwc.exe") u wait for the parent exe only ,but useing winwaitclose($iRet) u will wait for parent and chield process to close

Wait.  It is not Win handle, it is process PID.  That will not work.  You must mean ProcessWaitClose, right ?

Link to comment
Share on other sites

6 minutes ago, Network_Guy said:

change winwaitclose("qbwc.exe") to  winwaitclose($iRet) with killprocess /T 

 

If I understand correctly I should change this:

$iRet = Run("TaskKill /IM qbwc.exe /T /F")
ConsoleWrite("TaskKill " & $iRet & "/" & @error & @CRLF)
$iRet = ProcessWaitClose("qbwc.exe")

To this:

$iRet = Run("TaskKill /IM qbwc.exe /T /F")
ConsoleWrite("TaskKill " & $iRet & "/" & @error & @CRLF)
$iRet = ProcessWaitClose("$iRet")

Maybe I am misunderstanding. Wouldn't this just wait for the taskkill process to end instead of waiting for the qbwc.exe process to end?

Link to comment
Share on other sites

Link to comment
Share on other sites

1 minute ago, leo8888 said:

Wouldn't this just wait for the taskkill process to end instead of waiting for the qbwc.exe process to end?

Yes you are right.

Could you add those lines before the TaskKill :

Local $aList = ProcessList ("qbwc.exe")
_ArrayDisplay($aList)

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Updated the code as suggested. Array display output and ConsoleWrite output included below.

#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
local $iPID = 0
local $aList = 0

While 1
    Sleep(100) ; Sleep to reduce CPU usage
    If FileExists("e:\QuickBooks\ResetWebConnector.txt") Then   ; Check for trigger file
    Local $aList = ProcessList ("qbwc.exe")
    _ArrayDisplay($aList)
    $iRet = Run("TaskKill /IM qbwc.exe /T /F")
    ConsoleWrite("TaskKill " & $iRet & "/" & @error & @CRLF)
    $iRet = ProcessWaitClose("qbwc.exe")
    ConsoleWrite("WaitClose " & $iRet & "/" & @error & @CRLF)
    $iPID = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe")
    ConsoleWrite("Run " & $iPID & "/" & @error & @CRLF)
    $iRet = ProcessWait($iPID)
    ConsoleWrite("Wait " & $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)

 

ConsoleWrite output:

TaskKill 11716/0
WaitClose 1/0
Run 22192/0
Wait 22192/0

 

ArrayDisplay.png

Link to comment
Share on other sites

All I see is that the original process(23356) is effectively killed and a new process (22192) is effectively created.

Just for completeness.  Add the same 2 lines ProcessList/ArrayDisplay after the last ProcessWait.

 

Try put a sleep (2000) after FileDelete

Edited by Nine
Link to comment
Share on other sites

Updated code and all output. Notice the second array comes up blank. The ConsoleWrite output shows the qbwc.exe process is starting ok but it seems like it immediately disappears?

#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
local $iPID = 0
local $aList = 0

While 1
    Sleep(100) ; Sleep to reduce CPU usage
    If FileExists("e:\QuickBooks\ResetWebConnector.txt") Then   ; Check for trigger file
    Local $aList = ProcessList ("qbwc.exe")
    _ArrayDisplay($aList)
    $iRet = Run("TaskKill /IM qbwc.exe /T /F")
    ConsoleWrite("TaskKill " & $iRet & "/" & @error & @CRLF)
    $iRet = ProcessWaitClose("qbwc.exe")
    ConsoleWrite("WaitClose " & $iRet & "/" & @error & @CRLF)
    $iPID = Run("C:\Program Files (x86)\ServiceTitan\ServiceTitan QBWC\QBWC.exe")
    ConsoleWrite("Run " & $iPID & "/" & @error & @CRLF)
    $iRet = ProcessWait($iPID)
    Local $aList = ProcessList ("qbwc.exe")
    _ArrayDisplay($aList)
    ConsoleWrite("Wait " & $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)

 

TaskKill 17056/0
WaitClose 1/0
Run 23176/0
Wait 23176/0

 

array 1.png

array 2.png

Link to comment
Share on other sites

Ok the process is killed.  A new process is started but it is aborted soon after creation.  Well, maybe you need to specify a working directory :

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

I am starting run out of ideas here...

Link to comment
Share on other sites

8 minutes ago, JockoDundee said:

@leo8888, check the log files for qbwc, I believe it’s called QWCLOG.TXT.

 

I have that log file but it is only for the original version of the web connector that was supplied with quickbooks and has not been updated for months. 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.

I tried adding the full path to the command as Nine suggested but still no luck. I am thinking that this may not be something I can accomplish with AutoIT.

Sometimes things that should be simple turn out more complex than anticipated. I think this may be one of those times.

I really appreciate the time everyone has spent trying to find the issue with my code. I have learned a great deal just from the suggestions provided!

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