Jump to content

[For Work] Autoit application close when Windows session close


 Share

Recommended Posts

Hi all,

I had developped a script for my work and i have a problem.

The script is compiled. The problem is it can't stay loaded when i close TSE session to this server.

If i don't logoff, but close the TSE windows the script work well ( tested for seven day )

What i have tried :

- Launch by planified task, with local user account

- Launch by planified task, with local user account, task created in console mode

- Launch as service

- Launch with planified task at windows startup

The finality is to have the script always running in the machine and got access to graphical interface anytime

( it's why i have integrated minimize to systray in my script )

Nothing is working...

Here are function that I use :

#include <_AutoItErrorTrap.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <Constants.au3>
#include <Crypt.au3>
#include <Date.au3>
#include <Debug.au3>
#include <EditConstants.au3>
#Include <File.au3>
#include <GuiConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <SFTPEx_denis.au3>
#include <StaticConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <WindowsConstants.au3>

The script run under a Windows Server 2003 R2 standard Edtition with Service Pack 2

Does someone have idea, i think the solution is stupid, but for now i am very annoyed by this problem, and my client too :(

Thanks !

Edited by pinkfoyd
Link to comment
Share on other sites

  • Moderators

All you have done is post the includes in your script, how about posting the actual code so we can see what you're trying to do?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

The code is 1340 lines long... :geek:

Short describe : I use a graphical interface for scan a ftp, record entry in a database, send file to another server, then run sql request...

Not sure that the full code can help...

If it can help you here is the begining of the script ( the script WORK, i have only a problem when logoff from TSE )

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_SaveSource=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <_AutoItErrorTrap.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <Constants.au3>
#include <Crypt.au3>
#include <Date.au3>
#include <Debug.au3>
#include <EditConstants.au3>
#Include <File.au3>
#include <GuiConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <SFTPEx_denis.au3>
#include <StaticConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <WindowsConstants.au3>

Local $version = "v1.1a - (02/01/2013)"
Local $iSingleton = _SingletonPID('ktpftp', 1)
If $iSingleton = 0 Then
;~   test
Else
WinActivate("[CLASS:AutoIt v3 GUI]","")
exit
EndIf

;~ parametres pour systray
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
;~ parametre de la fonction executé en sortie du script
OnAutoItExitRegister ("_exit_process" )
;~ parametre de la gestion des erreurs
_AutoItErrorTrap("AutoItErrorTrap", "Une erreur a été détecté, Désolé." & @CRLF )
;~ parametre de la capture souris
GUIRegisterMsg($WM_NOTIFY, "MY_WM_COMMAND")

Local $database
Global $password_encrypt = ***
Global $log_file     = ***
Global $ini_file = @ScriptDir & "\ftp.ini"
Global $Conn, $ini_mode, $chemin_ftp , $timer_minutes, $pause=0 , $chemin_sauvegarde
Global $run_avant_purge = 50
Global $path_util = @ScriptDir & "\sp_ftp_xls\"

;~ Répertoire archive fichiers new deals avant intégration base
Global $path_archive_xml = ***"
Global $path_depot_xls =***

;~ Répertoire archive fichiers XLS
Global $path_archive_xls = ***
Global $mail_dest = IniRead($ini_file,"MAIL","TO","[NOT_FOUND]")
Global $mail_dest_cc = IniRead($ini_file,"MAIL","CC","[NOT_FOUND]")

;~ =================================== Creation de l'interface et reduction dans le systray ================================================
$Form = GUICreate("BULL Scan FTP/KTP/XML " & $version, 1024, 555, (@DesktopWidth-1024)/2 , (@DesktopHeight-555)/2 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Group_configuration = GUICtrlCreateGroup(" Configuration ", 8, 8, 465, 113)
$Combo_config = GUICtrlCreateCombo("", 24, 32, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetTip(-1, "Selection de la configuration de fonctionnement")
$Checkbox_defaut_config = GUICtrlCreateCheckbox("Configuration par défaut", 24, 64, 200, 17)
$Btn_info_config = GUICtrlCreateButton("Infos", 176, 31, 51, 25)
GUICtrlSetState($Btn_info_config,$GUI_DISABLE)

GUICtrlCreateLabel("Fréquence (minutes)", 321, 34, 100, 17)
$inp_nrb_minutes = GUICtrlCreateInput("", 424, 32, 25, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
GUICtrlSetTip($inp_nrb_minutes, "Frequence de scan du FTP en minutes")
GUICtrlSetLimit($inp_nrb_minutes, 3)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group_action = GUICtrlCreateGroup(" Actions ", 480, 8, 529, 113)
$btn_purge_bdd = GUICtrlCreateButton("Purge Database", 488, 32, 110, 25)
$btn_efface_element = GUICtrlCreateButton("Effacer un élément", 608, 32, 107, 25)
$btn_pause = GUICtrlCreateButton("Pause", 888, 24, 110, 25)
$btn_reprise = GUICtrlCreateButton("Reprise", 888, 88, 110, 25)
$btn_decrypte_ini = GUICtrlCreateButton("Decrypte INI File", 744, 32, 110, 25)
$btn_force_scan = GUICtrlCreateButton("Force Scan", 888, 56, 110, 25)
$btn_full_log = GUICtrlCreateButton("Fichier LOG", 744, 88, 110, 25)
$btn_clear_log = GUICtrlCreateButton("Efface Log", 488, 88, 110, 25)

GUICtrlCreateGroup("", -99, -99, 1, 1)
$list_file_bdd = GUICtrlCreateListView("Date|Heure|Nom", 8, 128, 1000, 266, $LVS_SORTDESCENDING ,BitOR($LVS_EX_REGIONAL, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GuiCtrlListView_SetColumnWidth($list_file_bdd, 0, 60)
_GuiCtrlListView_SetColumnWidth($list_file_bdd, 1, 50)
_GuiCtrlListView_SetColumnWidth($list_file_bdd, 2, 871)
$list_log = GUICtrlCreateListView("Date|Heure|Type|Information", 8, 400, 1000, 153, -1 ,BitOR($LVS_EX_REGIONAL, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GuiCtrlListView_SetColumnWidth($list_log, 0, 65)
_GuiCtrlListView_SetColumnWidth($list_log, 1, 55)
_GuiCtrlListView_SetColumnWidth($list_log, 2, 75)
_GuiCtrlListView_SetColumnWidth($list_log, 3, 778)

GUICtrlSetTip($list_log, "Activité")
;~ =================================== Fin interface ================================================
;~ mise en systray au demarrage
;~ GuiSetState(@SW_HIDE)
;~ TraySetState(1)

;Verifie que le .ini est crypté, sinon le fait
$section_name = IniReadSectionNames ( $ini_file )
$test_ini = IniRead($ini_file,$section_name[2],"URL","[NOT_FOUND]")
if StringLeft($test_ini,2) <> "0x" then _cryptage_fichier_ini("ENCODE")

; on lis le fichier INI pour avoir les information de base sur le fonctionnement du script
_load_ini_file()
;~ Verifie les parametres en entrée du script ftp_ktp.exe [ENCODE/DECODE] [Mot_de_passe] , les parametres sont facultatifs
;_check_arguments()

; Verifie que la base de donnée existe, sinon la créé, puis l'ouvre
;~ FileDelete(@ScriptDir & "\data.mdb")
$database = _check_database()

; on remplis l'interface avec les infos du .ini, du log et de la bdd
_remplissage_interface()
GUICtrlSetState($btn_efface_element,$GUI_DISABLE)
GUICtrlSetState($btn_reprise,$GUI_DISABLE)
GuiSetState(@SW_SHOW)

;~ GuiSetState(@SW_HIDE)
;~ TraySetState(1) ; show
;~ TraySetToolTip ("Afficher SCAN FTP XML KTP")
$start_time = _NowCalc()
_scan_files()
_refresh("FULL")
_purge_folder($path_archive_xls)
_purge_folder($path_archive_xml)

While 1
$msg = GuiGetMsg()

Switch $msg
     Case $GUI_EVENT_MINIMIZE
;~           GuiSetState(@SW_HIDE)
;~           TraySetState(1) ; show
;~           TraySetToolTip ("Afficher SCAN FTP XML KTP")
Case $btn_force_scan
_scan_files()
Case $Combo_config
_get_minute_mode()
Case $btn_efface_element
_efface_element()
Case $btn_decrypte_ini
_save_decrypt_ini_file()
Case $Checkbox_defaut_config
_change_default_mode()
Case $btn_full_log
ShellExecute("notepad.exe",$log_file)
Case $btn_clear_log
_clear_log()
Case $btn_purge_bdd
_purge_database()
Case $btn_pause
_mise_en_pause("Oui")
Case $btn_reprise
_mise_en_pause("Non")
     Case $GUI_EVENT_CLOSE
$iMsgBoxAnswer = MsgBox(52,"Attention","Voulez vous vraiment FERMER l'application ?" & @CRLF & "( Les fichiers ne seront plus traités. )")
if $iMsgBoxAnswer = 6 then ExitLoop
Case Else
if int (_DateDiff('s', $start_time, _NowCalc()) / 60) >= $timer_minutes AND $pause <> 1 then _scan_files()
EndSwitch

WEnd

Exit(0)


;~ ==================================================== FONCTIONS =============================================================
func _exit_process()

#cs
0 Natural closing.
1 close by Exit function.
2 close by clicking on exit of the systray.
3 close by user logoff.
4 close by Windows shutdown.
#ce

_SFTP_Close($Conn)
_SQLite_Close()
_SQLite_Shutdown()

_write_log("ARRET    - ExiCode : " & @ExitCode & " ExitMethod : " & @ExitMethod )

EndFunc
Edited by pinkfoyd
Link to comment
Share on other sites

One more information : if the TSE session lock, the script always run, the script is only killed if the TSE session is close

To be more clear : the script is launched by 'console' session, if i open a new TSE session, and close it, the script is killed...

Link to comment
Share on other sites

TSE : Terminal Server Edition, mstsc use under windows if you prefer, to open a distant session on a windows server.

No JoshOne, the code is good, and fully accomplished my client wishes, that I don't understand is why windows close the application... ( fact that i don't have with other executable SO IT'S a problem with autoit )

Edited by pinkfoyd
Link to comment
Share on other sites

  • Moderators

If it was fully accomplishing their wishes, you wouldn't be asking how to fix it. The point "JoshOne" :) was making is don't blame the language for mistakes in your code, it won't generally win you a lot of friends in these parts.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hum, seem we don't understand each other...

My code work ( testing for 7 day 24/24 without problem ), the fact is why the compiled EXE can't stay in memory when closing session while other EXE ( no autoit one ) stay alive...

Please stop saying i blame autoit it's not the point ! ( i used autoit for 7 years now and i love it ) The point is perhaps the compiler user some dll or something like that, that give me this problem.

Edited by pinkfoyd
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...