Coding Thread, A RunOnce that works at computer startup? in Coding and Web Development; Put a value in the classic HKLM\...\Runonce key and it is:
But that (apparently) ...
21st July 2010, 09:17 PM #1
A RunOnce that works at computer startup?
Put a value in the classic HKLM\...\Runonce key and it is:
But that (apparently) only happens when someone logs on, whereas I want the same behaviour but during computer start-up.
What I'm trying to do is figure out when a box has been rebooted between runs of an app i.e. code sets a "flag" somewhere which will be automatically disappeared during a reboot, and next time codes runs it checks to see if that flag is still there: Adding a RunOnce reg entry *almost* fits, except despite being in HKLM it (apparently) needs that logon.
The alternative I'd like to avoid is to stash a timestamp in the registry and then the next time code runs it does WMI to get last reboot time and compares that against my saved timestamp i.e. lastreboot > mytimestamp = rebooted.
 Don't google RunServicesOnce as an answer coz that's a Win 9x thing
21st July 2010, 09:22 PM #2
::bangs head on nearest wall::
Can't test this right now but using HKU instead might do it:
Ack - doesn't work.
Last edited by PiqueABoo; 21st July 2010 at 09:44 PM.
21st July 2010, 10:19 PM #3
Not sure I understand what you're trying to do, but a machine startup script will run before a user logs on. It will run at every startup but you could include logic to say "do I need to do <whatever>"
Similarly, you can schedule a task to run at system startup and include logic which checks to see if it needs to do something.
21st July 2010, 10:45 PM #4
Sadly no startup scripts or assumptions about domains are permitted - it's just some code occasionally running on a Windows box that sometimes might need to know if a reboot happened since the last time it ran.
22nd July 2010, 06:37 AM #5
Windows logs reboots in the event log - maybe reading that to check would do what you want...
22nd July 2010, 01:40 PM #6
Or you could check the uptime? Each check, log the time it ran and the uptime, then next time it ran use the two plus the new time and new uptime and some logic to see if the uptime is less than the time difference between time last checked and current time.
22nd July 2010, 07:46 PM #7
Yeah - those and the last-boot-time I mentioned will all work, but the prospect of just creating a reg value (data="") and using it's continuing presence to indicate that a desired reboot has not happened yet is much simpler, and I'm a big fan of simpler. Alas despite RunOnce being tantalisingly close I can't find an equivalent that will do the vanishing job before a post-reboot logon
PS: Looking at the boot time option earlier I discovered this:
Which might not seem like anything to get excited about, but up until now I've always used a clunky D-I-Y hand-crafted function to convert CIM format date strings to DateTimes. Who'd have thunk there was a ManagementDateTimeConverter you could just use?
Thanks to PiqueABoo from:
stratisphere (22nd July 2010)
22nd July 2010, 09:56 PM #8
Originally Posted by PiqueABoo
22nd July 2010, 10:11 PM #9
So, put the reg value there in your app and have a task scheduled to run "at startup" which just deletes that reg value. Seems pretty simple??
Originally Posted by PiqueABoo
By computer_expert in forum Jokes/Interweb Things
Last Post: 15th July 2010, 12:55 AM
By RabbieBurns in forum Windows
Last Post: 14th November 2009, 08:13 AM
By Little-Miss in forum Jokes/Interweb Things
Last Post: 12th July 2009, 09:19 PM
By noser in forum Windows
Last Post: 6th June 2008, 01:34 PM
Last Post: 17th November 2005, 12:06 AM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)