PiqueABoo Posted July 21, 2010 Posted July 21, 2010 Put a value in the classic HKLM\...\Runonce key and it is: a) remembered b) deleted c) run 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[1]. 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. [1] Don't google RunServicesOnce as an answer coz that's a Win 9x thing
PiqueABoo Posted July 21, 2010 Author Posted July 21, 2010 (edited) ::bangs head on nearest wall:: Can't test this right now but using HKU instead might do it: HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Runonce Ack - doesn't work. Edited July 21, 2010 by PiqueABoo
srochford Posted July 21, 2010 Posted July 21, 2010 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 " Similarly, you can schedule a task to run at system startup and include logic which checks to see if it needs to do something.
PiqueABoo Posted July 21, 2010 Author Posted July 21, 2010 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.
MattMitchell Posted July 22, 2010 Posted July 22, 2010 Windows logs reboots in the event log - maybe reading that to check would do what you want...
stratisphere Posted July 22, 2010 Posted July 22, 2010 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.
PiqueABoo Posted July 22, 2010 Author Posted July 22, 2010 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: ManagementDateTimeConverter.ToDateTime(mObj.Properties["LastBootUpTime"].Value.ToString()) 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? 1
stratisphere Posted July 22, 2010 Posted July 22, 2010 ManagementDateTimeConverter.ToDateTime(mObj.Properties["LastBootUpTime"].Value.ToString()) Awesome!
srochford Posted July 22, 2010 Posted July 22, 2010 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. 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??
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now