FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour exe in background
Posts: 434
Joined: Wed Jun 06, 2007 02:58 PM
exe in background
Posted: Thu Jan 24, 2019 01:13 PM

hi,
I'd like your advice to this situation.
I have a folder in my lan, in this folder some users put files txt (about one each 15 or 20 minutes)
for aech file I need to read it inside and print some information.
therefore I have to create a .exe that is always active (in background) and start print when it finds a new .txt into the folder.

can you help me?

thanks

FiveWin for xHarbour 24.02 - Feb. 2024 - Embarcadero C++ 7.60 for Win32 Copyright (c) 1993-2023

FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)

Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: exe in background
Posted: Thu Jan 24, 2019 01:28 PM
Code (fw): Select all Collapse
Do While PathFileExists("c:\blabla\qqfoi.txt") = 0
    SysWait(.3)

...
EndDo


DLL32 FUNCTION PathFileExists(cPathFileName AS STRING) AS LONG PASCAL ;
      FROM "PathFileExistsA" LIB "shlwapi.dll"
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: exe in background
Posted: Thu Jan 24, 2019 01:29 PM

\samples\testtray.prg

Regards.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 434
Joined: Wed Jun 06, 2007 02:58 PM
Re: exe in background
Posted: Thu Jan 24, 2019 03:53 PM

thank you karinha, I'll try it

FiveWin for xHarbour 24.02 - Feb. 2024 - Embarcadero C++ 7.60 for Win32 Copyright (c) 1993-2023

FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)

Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: exe in background
Posted: Fri Jan 25, 2019 07:57 AM

Hello,
I think you should use a timer.
I tested your suggestion with syswait in a loop.
This is consuming 25% of CPU.
Best regards
Otto

Posts: 434
Joined: Wed Jun 06, 2007 02:58 PM
Re: exe in background
Posted: Fri Jan 25, 2019 08:21 AM

hi Otto,
thank you, any example with timer?

FiveWin for xHarbour 24.02 - Feb. 2024 - Embarcadero C++ 7.60 for Win32 Copyright (c) 1993-2023

FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)

Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: exe in background
Posted: Fri Jan 25, 2019 08:35 AM
Hello,
attached a sample.
This is my anti ransomware program. :-)
This program monitors the data folder.
Only dbf, ftp and cdx files are allowed in the data folder. If a ransomware tries to encrypt a file, the bat-file is called with the shutdown command.
best regards
Otto

Best regards
Otto



Code (fw): Select all Collapse
#include "FiveWin.ch"
static oWnd, oTimer
//----------------------------------------------------------------------------//

function Main()
   DEFINE DIALOG oWnd FROM 3, 3 TO 20, 50 ;
      TITLE OemToAnsi( "Testing timers" )

   ACTIVATE DIALOG oWnd ;
      ON INIT  StartTimer()

return nil

//----------------------------------------------------------------------------//
function StartTimer()
   DEFINE TIMER oTimer OF oWnd ;
      INTERVAL 300 ;
      ACTION ( check() )

   ACTIVATE TIMER oTimer
return nil
//----------------------------------------------------------------------------//


function check()
   local aDir   := directory( "x:\xwhdaten\DATAWIN\" + "*.*","DHS")
   local I := 1
   local cFilename := ""
   local lFehler := .f.
   local cFehler := ""

   oTimer:Deactivate()



   FOR I := 1 to len( aDir )
      lFehler := .T.

      if    aDir[ I , 1 ]  <>  "."
         if ALLTRIM ( UPPER( cFileExt( aDir[ I , 1 ] ) ) ) = "DBF"
            lFehler := .f.
         endif
         if UPPER( cFileExt( aDir[ I , 1 ] ) ) = "FPT"
            lFehler := .f.
         endif
         if UPPER( cFileExt( aDir[ I , 1 ] ) ) = "CDX"
            lFehler := .f.
         endif
         if lFehler = .t.
            cFehler += aDir [ I, 1 ] + CRLF
            FWLOG cFehler
            winexec( "abmelden.bat" )
         endif

      endif
   next

   oTimer:activate()
return nil
*******************
abmelden.bat
shutdown -S
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: exe in background
Posted: Fri Jan 25, 2019 08:42 AM

Hello,

>I have a folder in my lan, in this folder some users put files txt (about one each 15 or 20 minutes)

Is the program that writes the TXT files from you. If so then you should create a lock file write the TXT file and then delete the lock file again.
The program with the timer () may only edit the TXT files if there is no lock file.

Best regards
Otto

Posts: 434
Joined: Wed Jun 06, 2007 02:58 PM
Re: exe in background
Posted: Fri Jan 25, 2019 09:23 AM

hi Otto,
txt files in the folder are generated by others application (not mine).
Pratically, there are some users that works with CAD, this CAD make nesting of iron sheet for mecanichal parts end this parts are in txt files in the folder.
I have to intercept this files when it is generated, my exe when there is a new txt have to read inside and print list of parts of txt.

FiveWin for xHarbour 24.02 - Feb. 2024 - Embarcadero C++ 7.60 for Win32 Copyright (c) 1993-2023

FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)

Visual Studio 2019 - Pelles C V.8.00.60 (Win64)

Continue the discussion