Jump to content

Recommended Posts

Posted

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

Posted (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 by PiqueABoo
Posted

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.

Posted
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.
Posted
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.
Posted

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?

  • Thanks 1
Posted
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??

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...