Page 1 of 1

exe in background

PostPosted: Thu Jan 24, 2019 1:13 pm
by damianodec
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

Re: exe in background

PostPosted: Thu Jan 24, 2019 1:28 pm
by karinha
Code: Select all  Expand view


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"  
 

Re: exe in background

PostPosted: Thu Jan 24, 2019 1:29 pm
by karinha
\samples\testtray.prg

Regards.

Re: exe in background

PostPosted: Thu Jan 24, 2019 3:53 pm
by damianodec
thank you karinha, I'll try it

Re: exe in background

PostPosted: Fri Jan 25, 2019 7:57 am
by Otto
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

Re: exe in background

PostPosted: Fri Jan 25, 2019 8:21 am
by damianodec
hi Otto,
thank you, any example with timer?

Re: exe in background

PostPosted: Fri Jan 25, 2019 8:35 am
by Otto
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: Select all  Expand view

#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  





Re: exe in background

PostPosted: Fri Jan 25, 2019 8:42 am
by Otto
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

Re: exe in background

PostPosted: Fri Jan 25, 2019 9:23 am
by damianodec
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.