Modify dmg's Log Out logger to standby/hibernate logger

Get help with using AutoHotkey and its commands and hotkeys
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Modify dmg's Log Out logger to standby/hibernate logger

24 Jan 2014, 14:19

Hi!

Ok, now it's getting a bit too complicated for me. Firstly I'm on Win7 32-bit and dmg´s original script doesn't seem to log logouts correct when using 0x80000000. Instead it gets logged as a shutdown. If changing to the corresponding integer -2147483648 I get correct logging. Why is that? Secondly I have no idea how to pick apart logging for "System hibernation" and "System resuming from hibernation" when not enitierly knowing whats the integer for these two are. My aim is to get the script to log standbys/hibernates as well. Maybe someone can help me out? Here's the Log out logger script I'm using with changes and comments for changed parts:

Code: Select all

#noenv
#singleinstance, ignore
setbatchlines, 10ms
setworkingdir, %a_scriptdir%
;---------------------------------------------------------create files if not present.
fileinstall, readme.txt, readme.txt, 0
fileinstall, settings.ini, settings.ini, 0

sleep, 20
;---------------------------------------------------------read installation and icon settings.
iniread, installed, settings.ini, settings, installed
iniread, tray, settings.ini, settings, tray
;---------------------------------------------------------if there is a tray icon, create tray menu.
if tray = no
 {
   menu, tray, noicon
 }
else
 {
   menu, tray, nostandard
   menu, tray, add, View log, view
   menu, tray, add, Edit settings, edit
   menu, tray, add
   menu, tray, add, Uninstall, uninstall
   menu, tray, add, Exit, exit
   menu, tray, default, View log
   menu, tray, icon, D:\TV\test\Shutdownlogger\glasses.ico
 }
;---------------------------------------------------------if not installed, start installing.
if installed = 0
 {
   msgbox, 33, Install, Welcome to Log Out Logger`, a simple`nutility to monitor system startup and`nshutdown. Do you want to install`nand start using Log Out Logger?, 20

   ifmsgbox, cancel
    {
      goto, exit
    }
   ifmsgbox, timeout
    {
      goto, exit
    }
   ifmsgbox, ok
    {
      filecreateshortcut, %a_scriptfullpath%, %a_startup%\Log Out Logger.lnk
      iniwrite, 1, settings.ini, settings, Installed
      msgbox, 64, Install, Log Out Logger has been installed and`nwill start monitoring on next system log in., 10
      goto, exit
    }
 }

continue:
;---------------------------------------------------------if uninstall, start uninstalling.
if installed = uninstall
 {
   msgbox, 33, Uninstall, Are you sure you want to uninstall Log Out Logger?, 20
   
   ifmsgbox, ok
    {
      filedelete, %a_startup%\Log Out Logger.lnk
      iniwrite, 0, settings.ini, settings, Installed
      msgbox, 64, Uninstall, Log Out Logger has been uninstalled.`nYou may now delete the application`nfiles from your system., 10
      goto, exit
    }
   ifmsgbox, cancel
    {
      iniwrite, 1, settings.ini, settings, Installed
      return
    }
   ifmsgbox, timeout
    {
      goto, exit
    }
 }
;---------------------------------------------------------log start up time and start monitoring for shutdown.
fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - System log in.`n, log.txt
onmessage(0x11, "on_shutdown") ; WM_QUERYENDSESSION = 0x11
onmessage(0x218, "on_shutdown") ; WM_POWERBROADCAST = 0x218
;---------------------------------------------------------start timer to clear memory every 10 minutes. end autoexecute.
settimer, emptymem, 600000
return
;---------------------------------------------------------menu item, view log.
view:
 {
   ifnotexist, log.txt
    {
      msgbox, 48, Error, Log file not found!, 10
    }
   else
    {
      run, log.txt
    }
 }
return
;---------------------------------------------------------menu item, edit settings.
edit:
 {
   ifnotexist, settings.ini
    {
      msgbox, 48, Error, Settings file not found. Please restart to generate default settings., 10
    }
   else
    {
      run, settings.ini
    }
 }
return
;---------------------------------------------------------menu item, uninstall.
uninstall:
 {
   iniwrite, uninstall, settings.ini, settings, Installed
   iniread, installed, settings.ini, settings, installed
   goto, continue
 }
return
;---------------------------------------------------------menu item, exit program.
exit:
 {
   exitapp
 }
return
;---------------------------------------------------------function to be called on shutdown or log out.
on_shutdown(param1, param2) ;
 {
   if param2 = -2147483648 ;The original 0x80000000 doesn't work ;check if log out.
    {
      fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - User has logged out.`n, log.txt
    }
   else ;if not log out then shutdown.
    {
      fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - System shutdown.`n, log.txt
    }
   if param1 = ??? ; integer for system hibernation seems to be 4
     {
      fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - System hibernation.%param1% > %param2%`n, log.txt
     }
   if param1 = ??? ; integer for resuming hibernation seems to be either 18 or 7. 
     {
      fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - System resuming from hibernation.%param1% > %param2%`n, log.txt
     }
 }
return
;---------------------------------------------------------clear memory function.
emptymem:
 {
   dllcall("psapi.dll\EmptyWorkingSet", "UInt", -1)
 }
return
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: Modify dmg's Log Out logger to standby/hibernate logger

25 Jan 2014, 04:03

Ok, this seems to work, based on trial and error. Dont know if it will work in every case though, know nada about C. However checking which params (integers) are returned and use them like this it works satisfying.

Code: Select all

#noenv
#singleinstance, ignore
setbatchlines, 10ms
setworkingdir, %a_scriptdir%
;---------------------------------------------------------create files if not present.
fileinstall, readme.txt, readme.txt, 0
fileinstall, settings.ini, settings.ini, 0

sleep, 20
;---------------------------------------------------------read installation and icon settings.
iniread, installed, settings.ini, settings, installed
iniread, tray, settings.ini, settings, tray
;---------------------------------------------------------if there is a tray icon, create tray menu.
if tray = no
 {
   menu, tray, noicon
 }
else
 {
   menu, tray, nostandard
   menu, tray, add, View log, view
   menu, tray, add, Edit settings, edit
   menu, tray, add
   menu, tray, add, Uninstall, uninstall
   menu, tray, add, Exit, exit
   menu, tray, default, View log
   menu, tray, icon, D:\TV\test\Shutdownlogger\glasses.ico
 }
;---------------------------------------------------------if not installed, start installing.
if installed = 0
 {
   msgbox, 33, Install, Welcome to Log Out Logger`, a simple`nutility to monitor system startup and`nshutdown. Do you want to install`nand start using Log Out Logger?, 20

   ifmsgbox, cancel
    {
      goto, exit
    }
   ifmsgbox, timeout
    {
      goto, exit
    }
   ifmsgbox, ok
    {
      filecreateshortcut, %a_scriptfullpath%, %a_startup%\Log Out Logger.lnk
      iniwrite, 1, settings.ini, settings, Installed
      msgbox, 64, Install, Log Out Logger has been installed and`nwill start monitoring on next system log in., 10
      goto, exit
    }
 }

continue:
;---------------------------------------------------------if uninstall, start uninstalling.
if installed = uninstall
 {
   msgbox, 33, Uninstall, Are you sure you want to uninstall Log Out Logger?, 20
   
   ifmsgbox, ok
    {
      filedelete, %a_startup%\Log Out Logger.lnk
      iniwrite, 0, settings.ini, settings, Installed
      msgbox, 64, Uninstall, Log Out Logger has been uninstalled.`nYou may now delete the application`nfiles from your system., 10
      goto, exit
    }
   ifmsgbox, cancel
    {
      iniwrite, 1, settings.ini, settings, Installed
      return
    }
   ifmsgbox, timeout
    {
      goto, exit
    }
 }
;---------------------------------------------------------log start up time and start monitoring for shutdown.
fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - System log in.`n, log.txt
onmessage(0x11, "on_shutdown")
onmessage(0x218, "on_shutdown")
;---------------------------------------------------------start timer to clear memory every 10 minutes. end autoexecute.
settimer, emptymem, 600000
return
;---------------------------------------------------------menu item, view log.
view:
 {
   ifnotexist, log.txt
    {
      msgbox, 48, Error, Log file not found!, 10
    }
   else
    {
      run, log.txt
    }
 }
return
;---------------------------------------------------------menu item, edit settings.
edit:
 {
   ifnotexist, settings.ini
    {
      msgbox, 48, Error, Settings file not found. Please restart to generate default settings., 10
    }
   else
    {
      run, settings.ini
    }
 }
return
;---------------------------------------------------------menu item, uninstall.
uninstall:
 {
   iniwrite, uninstall, settings.ini, settings, Installed
   iniread, installed, settings.ini, settings, installed
   goto, continue
 }
return
;---------------------------------------------------------menu item, exit program.
exit:
 {
   exitapp
 }
return
;---------------------------------------------------------function to be called on shutdown or log out.
on_shutdown(param1, param2) ;
 {
   if param2 = -2147483648 ;check if log out.
    {
      fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - User has logged out.`n, log.txt
    }
   if (param1 = 0 and param2 = 0) ;check if shutdown.
    {
      fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - System shutdown.`n, log.txt
    }
   if param1 = 4 ; check if standby/hibernate
     {
      fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - System standby/hibernation.`n, log.txt
     }
   if param1 = 7 ;check if resume from standby/hibernation 
     {
      fileappend, %a_dd%/%a_mm%/%a_yyyy% %a_hour%:%a_min% - Resume from standby/hibernation.`n, log.txt
     }
 }
return
;---------------------------------------------------------clear memory function.
emptymem:
 {
   dllcall("psapi.dll\EmptyWorkingSet", "UInt", -1)
 }
return
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: Modify dmg's Log Out logger to standby/hibernate logger

26 Jan 2014, 12:25

Zelio wrote:-2147483648 = 0xFFFFFFFF80000000 (64 bit and signed problem I guess)
That is what puzzles me. I'm on Windows 7 32-bit and using AHK_H 32-bit and still it didn't work with 0x80000000. Well, it doesn't matter as long as it works with -2147483648. Nice script by DMG btw...have been searching for something like that for years which was easy to modify for logging of standby/hibernates as well :)

Return to “Ask For Help”

Who is online

Users browsing this forum: AmDeG 11, boiler, Bugz000, flyingDman, malaysoni, SuperFoobar and 205 guests