exe in background

exe in background

Postby damianodec » Thu Jan 24, 2019 1: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 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 414
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: exe in background

Postby karinha » Thu Jan 24, 2019 1:28 pm

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"  
 
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: exe in background

Postby karinha » Thu Jan 24, 2019 1:29 pm

\samples\testtray.prg

Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: exe in background

Postby damianodec » Thu Jan 24, 2019 3:53 pm

thank you karinha, I'll try it
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 414
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: exe in background

Postby Otto » Fri Jan 25, 2019 7: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6073
Joined: Fri Oct 07, 2005 7:07 pm

Re: exe in background

Postby damianodec » Fri Jan 25, 2019 8:21 am

hi Otto,
thank you, any example with timer?
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 414
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: exe in background

Postby Otto » Fri Jan 25, 2019 8: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: 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  




********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6073
Joined: Fri Oct 07, 2005 7:07 pm

Re: exe in background

Postby Otto » Fri Jan 25, 2019 8: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6073
Joined: Fri Oct 07, 2005 7:07 pm

Re: exe in background

Postby damianodec » Fri Jan 25, 2019 9: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 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 414
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 38 guests