Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi System Reboot Counter (https://www.delphipraxis.net/200366-system-reboot-counter.html)

Der schöne Günther 15. Apr 2019 08:20

AW: System Reboot Counter
 
He does not want to block reboots. He has his application already registered in auto start, but does not want his application to run for the next two times the system boots.

Trying to get your application out of the "RunOnce" thing and then back in is the wrong approach, in my opinion. Why don't you just keep track of the reboot counter when your setup (or whatever it is) starts, and when your application launches, you compare if the boot count is greater than
Delphi-Quellcode:
saved_bootcount + 2
. If not, just exit your application.

dummzeuch 15. Apr 2019 08:20

AW: System Reboot Counter
 
OK, as far as I understand you want your program to execute an action on every second reboot.

This is how I would implement this:

* Add your program to the autostart.
* When it starts, read the reboot counter mentioned above. Compare it to your own registry entry (under HKCU\Software\<your company>\<your program>).
* If your entry does not exist, assume that this is the first time your program was started, execute the action.
* If your entry exists, compare its value to the reboot counter. If the difference is <=1 skip the action, otherwise excute the action.
* Write the reboot counter to your registry entry and exit.

Note that this will only work if it is always the same user who works on that computer. Otherwise you will need keep your own counter somewhere else but HKCU, because that entry is user dependent.

Moombas 15. Apr 2019 09:58

AW: System Reboot Counter
 
Zitat:

Zitat von dummzeuch (Beitrag 1430305)
OK, as far as I understand you want your program to execute an action on every second reboot.

This is how I would implement this:

* Add your program to the autostart.
* When it starts, read the reboot counter mentioned above. Compare it to your own registry entry (under HKCU\Software\<your company>\<your program>).
* If your entry does not exist, assume that this is the first time your program was started, execute the action.
* If your entry exists, compare its value to the reboot counter. If the difference is <=1 skip the action, otherwise excute the action.
* Write the reboot counter to your registry entry and exit.

Note that this will only work if it is always the same user who works on that computer. Otherwise you will need keep your own counter somewhere else but HKCU, because that entry is user dependent.

Another "solution" would be to write it in a file (e.g. ini file in working directory). That would be user unindependent. Maybe create it when needed, and delete it when ready.

SlpLow 15. Apr 2019 17:19

AW: System Reboot Counter
 
Thank you very much! Now I have no doubt in the logic of performing the task.

Sherlock 16. Apr 2019 07:34

AW: System Reboot Counter
 
And on a side note, consider visiting our English speaking sister site https://en.delphipraxis.net/
Not that there is anything wrong with posting in english here, but you might get faster responses, as it is international and users there come from all timezones.

Sherlock


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:13 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz