Recent

Author Topic: Detecting user logon and logoff in a Windows service (Lazarus daemon)  (Read 10033 times)

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #15 on: August 11, 2020, 10:56:26 am »
Thanks for your clarifications. I realised that 3.3.1 was a development version but got lost in the detail of how to install it, and wasn't aware of the patch utility. I will follow the instructions later today.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #16 on: August 12, 2020, 05:43:46 pm »
Sorry, another problem - the PATCH utility isn't on my PC: please see the attached image. It isn't on my other PC with 3.0.0 either. I have a utility called "Search Everything" and it didn't find it anywhere on either PC. Can you tell me how/where to get it?
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #17 on: August 12, 2020, 08:06:30 pm »
My installation of Lazarus/FPC is installed to:  C:\Programs\Lazarus.Fixes

And I have this (attached):

Do you get anything that turns up if you run the following at a command prompt?

Code: [Select]
DIR C:\Lazarus\patch.exe /s /a
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #18 on: August 12, 2020, 08:16:53 pm »
My installation of Lazarus/FPC is installed to:  C:\Programs\Lazarus.Fixes

And I have this (attached):

Do you get anything that turns up if you run the following at a command prompt?

Code: [Select]
DIR C:\Lazarus\patch.exe /s /a

Thanks, but no, I don't. I can see the command looks in the Lazarus folder and its subfolders but, for me, it spends a few seconds searching and then returns "File not found".
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #19 on: August 12, 2020, 09:35:18 pm »
Sorry, another problem - the PATCH utility isn't on my PC: please see the attached image. It isn't on my other PC with 3.0.0 either. I have a utility called "Search Everything" and it didn't find it anywhere on either PC. Can you tell me how/where to get it?

Strange... maybe it's part of the i386-win32 addon? Cause I have that installed as well...

Anyway, you should be able to get it from here as well. Alternatively you could add the changes manually...

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #20 on: August 12, 2020, 10:12:17 pm »
Strange... maybe it's part of the i386-win32 addon? Strange... maybe it's part of the i386-win32 addon? Cause I have that installed as well...

That's a good point.  I also have the add-on for deploying 32-bit Windows code.
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #21 on: August 14, 2020, 03:06:04 pm »
I'm either really unlucky with this project or just plain stupid. I've now got the patch executable but can't get it to work. Can anybody see what I'm doing wrong here? As far as I can tell, the system is telling me that a file doesn't exist which obviously does.

Code: Text  [Select][+][-]
  1. c:\lazarus\fpc\3.2.0\source>c:\lazarus\fpc\3.2.0\bin\x86_64-win64\patch -Np 1 -i c:\lazpatches\fcl-extra-43626.patch
  2. c:\lazarus\fpc\3.2.0\bin\x86_64-win64\patch: **** Can't open patch file c:\lazpatches\fcl-extra-43626.patch : No such file or directory
  3.  
  4. c:\lazarus\fpc\3.2.0\source>dir C:\lazpatches
  5.  Volume in drive C is OS
  6.  Volume Serial Number is AC27-A577
  7.  
  8.  Directory of C:\lazpatches
  9.  
  10. 12/08/2020  16:30    <DIR>          .
  11. 12/08/2020  16:30    <DIR>          ..
  12. 12/08/2020  16:24             4,257 fcl-extra-46326.patch
  13. 12/08/2020  16:24             5,574 fcl-extra-46327.patch
  14. 12/08/2020  16:30    <DIR>          src_backup
  15.                2 File(s)          9,831 bytes
  16.                3 Dir(s)  713,456,386,048 bytes free

Does it matter if I rename the patch files to something brief and simple like 1.patch and 2.patch, or is there an internal check that would prevent this working?
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #22 on: August 14, 2020, 03:11:33 pm »
I don't use "patch" app, I always run "svn patch <filename>". And with RELATIVE filename.

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #23 on: August 14, 2020, 03:15:59 pm »
I don't use "patch" app, I always run "svn patch <filename>". And with RELATIVE filename.

Thanks. I created copies of the patch files called 1.patch and 2.patch and the utility was able to find them, so that seems to have worked.

I guess I'm seeing an undocumented bug in Windows long file names because I also had a "file not found" with Windows' fc the other day, even after double-checking the name.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #24 on: August 14, 2020, 04:19:41 pm »
I've applied the two patches

I followed the first part of your instruction and the patches seemed to apply successfully. However, things went wrong again at this stage:

Quote from: PascalDragon on August 11, 2020, 10:09:03 am
Quote
After that you go to the packages\fcl-extra directory and execute the following command (the same remark regarding PATH as for patch applies for fpc):

Code: Text  [Select][+][-]
  1. fpc -FU..\..\..\units\x86_64-win64\fcl-extra -Fiwin daemonapp.pp

(Note: if you use a 32-bit Lazarus then you need to use i386-win32 instead of x86_64-win64)

After that you rebuild Lazarus and everything should be set.
I tried the FPC command both without and then with the full path before daemonapp.pp. Both times it failed with an error:
Code: Text  [Select][+][-]
  1. c:\lazarus\fpc\3.2.0\source\packages\fcl-extra>c:\lazarus\fpc\3.2.0\bin\x86_64-win64\fpc -FU C:\lazarus\fpc\3.2.0\units\x86_64-win64\fcl-extra -Fiwin c:\lazarus\fpc\3.2.0\source\packages\fcl-extra\src\daemonapp.pp
  2. Warning: Only one source file supported, changing source file to compile from "C:\lazarus\fpc\3.2.0\units\x86_64-win64\fcl-extra" into "c:\lazarus\fpc\3.2.0\source\packages\fcl-extra\src\daemonapp.pp"
  3. Free Pascal Compiler version 3.2.0 [2020/07/07] for x86_64
  4. Copyright (c) 1993-2020 by Florian Klaempfl and others
  5. Target OS: Win64 for x64
  6. Compiling c:\lazarus\fpc\3.2.0\source\packages\fcl-extra\src\daemonapp.pp
  7. daemonapp.pp(461,2) Fatal: Cannot open include file "daemonapp.inc"
  8. Fatal: Compilation aborted
  9. Error: c:\lazarus\fpc\3.2.0\bin\x86_64-win64\ppcx64.exe returned an error exitcode
  10.  
The command line was invoked with "Run as Administrator". I guess the problem is being unable to find daemonapp.inc, but I don't know how to fix that. (I have C:\lazarus\fpc\3.2.0\bin\x86_64-win64 in my Windows path.)
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #25 on: August 14, 2020, 04:51:13 pm »
Ah, sorry, small mixup there. You should go to packages\fcl-extra\src (a subdirectory of where you are).

And don't add a space between -FU and the directory.

The full command line should now be this:

Code: [Select]
c:\lazarus\fpc\3.2.0\source\packages\fcl-extra\src>c:\lazarus\fpc\3.2.0\bin\x86_64-win64\fpc -FUC:\lazarus\fpc\3.2.0\units\x86_64-win64\fcl-extra -Fiwin daemonapp.pp

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #26 on: August 15, 2020, 04:34:42 pm »
Thanks but it still won't work for me, I'm afraid.

Code: Text  [Select][+][-]
  1. C:\lazarus\fpc\3.2.0\source\packages\fcl-extra\src>c:\lazarus\fpc\3.2.0\bin\x86_64-win64\fpc -FUC:\lazarus\fpc\3.2.0\units\x86_64-win64\fcl-extra -Fiwin daemonapp.pp
  2. Free Pascal Compiler version 3.2.0 [2020/07/07] for x86_64
  3. Copyright (c) 1993-2020 by Florian Klaempfl and others
  4. Target OS: Win64 for x64
  5. Compiling daemonapp.pp
  6. daemonapp.inc(34,10) Warning: Function result does not seem to be set
  7. daemonapp.inc(40,80) Warning: Converting pointers to signed integers may result in wrong comparison results and range errors, use an unsigned type instead.
  8. daemonapp.inc(249,31) Warning: Local variable "IDTag" does not seem to be initialized
  9. daemonapp.inc(526,13) Warning: Symbol "Resume" is deprecated
  10. daemonapp.inc(547,29) Warning: Symbol "Resume" is deprecated
  11. daemonapp.inc(597,27) Error: Identifier not found "SERVICE_ACCEPT_USERMODEREBOOT"
  12. daemonapp.pp(1350,12) Warning: Symbol "Suspend" is deprecated
  13. daemonapp.pp(1520) Fatal: There were 1 errors compiling module, stopping
  14. Fatal: Compilation aborted
  15. Error: c:\lazarus\fpc\3.2.0\bin\x86_64-win64\ppcx64.exe returned an error exitcode
  16.  

Does the "Identifier not found" error mean the patches weren't applied correctly? I didn't see any errors when I applied them.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #27 on: August 16, 2020, 01:59:37 pm »
Did you do this part I had written to you in my original post about my changes?

Quote
You then need to do a slight adjustment in packages/fcl-extra/src/win/daemonapp.inc: in TDaemonController.ReportStatus.GetAcceptedCodes you need to disable the handling of wccTimeChange, wccTriggerEvent and wccUserModeReboot (this way you don't need to add revision 46325 as well which might lead to the need to compile more than necessary).

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #28 on: August 16, 2020, 04:55:12 pm »
Did you do this part I had written to you in my original post about my changes?

Quote
You then need to do a slight adjustment in packages/fcl-extra/src/win/daemonapp.inc: in TDaemonController.ReportStatus.GetAcceptedCodes you need to disable the handling of wccTimeChange, wccTriggerEvent and wccUserModeReboot (this way you don't need to add revision 46325 as well which might lead to the need to compile more than necessary).

Oops! Sorry, I didn't - just realised I've missed that step. I'll do the missing step and then try again. Thanks.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

TyneBridges

  • Full Member
  • ***
  • Posts: 150
    • Personal blog
Re: Detecting user logon and logoff in a Windows service (Lazarus daemon)
« Reply #29 on: August 17, 2020, 03:36:17 pm »
I tried again after commenting out the specified bit of daemonapp.inc and got the following. I assume the notes and warnings are not critical. There is a lot of conflicting info online about how to rebuild Lazarus but doing it from the Tools menu within the IDE seemed to work.
Code: Text  [Select][+][-]
  1. c:\lazarus\fpc\3.2.0\bin\x86_64-win64\fpc -FUC:\lazarus\fpc\3.2.0\units\x86_64-win64\fcl-extra -Fiwin daemonapp.pp
  2.  
  3. C:\lazarus\fpc\3.2.0\source\packages\fcl-extra\src>c:\lazarus\fpc\3.2.0\bin\x86_64-win64\fpc -FUC:\lazarus\fpc\3.2.0\units\x86_64-win64\fcl-extra -Fiwin daemonapp.pp
  4. Free Pascal Compiler version 3.2.0 [2020/07/07] for x86_64
  5. Copyright (c) 1993-2020 by Florian Klaempfl and others
  6. Target OS: Win64 for x64
  7. Compiling daemonapp.pp
  8. daemonapp.inc(34,10) Warning: Function result does not seem to be set
  9. daemonapp.inc(40,80) Warning: Converting pointers to signed integers may result in wrong comparison results and range errors, use an unsigned type instead.
  10. daemonapp.inc(249,31) Warning: Local variable "IDTag" does not seem to be initialized
  11. daemonapp.inc(526,13) Warning: Symbol "Resume" is deprecated
  12. daemonapp.inc(547,29) Warning: Symbol "Resume" is deprecated
  13. daemonapp.inc(556,28) Warning: Function result does not seem to be set
  14. daemonapp.pp(845,3) Note: Local variable "C" not used
  15. daemonapp.pp(946,3) Note: Local variable "D" is assigned but never used
  16. daemonapp.pp(1062,3) Note: Local variable "ControlCodes" not used
  17. daemonapp.pp(1296,3) Note: Local variable "CC" is assigned but never used
  18. daemonapp.pp(1297,3) Note: Local variable "S" is assigned but never used
  19. daemonapp.pp(1350,12) Warning: Symbol "Suspend" is deprecated
  20. daemonapp.pp(249,5) Note: Private field "TDaemonDef.FServiceName" is never used
  21. daemonapp.pp(362,5) Note: Private field "TCustomDaemonApplication.FControllerCount" is never used
  22. daemonapp.pp(466,3) Note: Local variable "DesignMapper" not used
  23. Writing Resource String Table file: daemonapp.rsj
  24. 2198 lines compiled, 0.3 sec
  25. 7 warning(s) issued
  26. 8 note(s) issued
  27.  
I got stuck again when going back to this instruction:
Quote
...you need to go to your daemon's definition in the Daemon Mapper and inside winbindings.AcceptedCodes enable wccSessionChange.
I started a new project and selected Service as the project type but, even after manually loading DaemonMapperUnit1 in the Project Inspector, "Find in files" couldn't find any reference to winbindings.AcceptedCodes. Do I need to edit Lazarus' source code again rather than the code it generates for my service?

Thanks for your help.
John H, north east England
Lover of the old Delphi, still inexperienced with FPC/Lazarus and not an instinctive programmer

 

TinyPortal © 2005-2018