+ Post New Thread
Results 1 to 9 of 9
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: a) remembered b) deleted c) run But that (apparently) ...
  1. #1

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115

    A RunOnce that works at computer startup?

    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

  2. #2

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115
    ::bangs head on nearest wall::
    Can't test this right now but using HKU instead might do it:
    HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\Cur rentVersion\Runonce

    Ack - doesn't work.
    Last edited by PiqueABoo; 21st July 2010 at 08:44 PM.

  3. #3

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    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.

  4. #4

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115
    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.

  5. #5

    Join Date
    May 2009
    Location
    Sheffield
    Posts
    243
    Thank Post
    22
    Thanked 35 Times in 26 Posts
    Rep Power
    20
    Windows logs reboots in the event log - maybe reading that to check would do what you want...

  6. #6
    stratisphere's Avatar
    Join Date
    Apr 2007
    Posts
    295
    Thank Post
    33
    Thanked 87 Times in 31 Posts
    Rep Power
    30
    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.

  7. #7

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115
    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.Proper ties["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?

  8. Thanks to PiqueABoo from:

    stratisphere (22nd July 2010)

  9. #8
    stratisphere's Avatar
    Join Date
    Apr 2007
    Posts
    295
    Thank Post
    33
    Thanked 87 Times in 31 Posts
    Rep Power
    30
    Quote Originally Posted by PiqueABoo View Post
    ManagementDateTimeConverter.ToDateTime(mObj.Proper ties["LastBootUpTime"].Value.ToString())
    Awesome!

  10. #9

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    Quote Originally Posted by PiqueABoo View Post
    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??

SHARE:
+ Post New Thread

Similar Threads

  1. [Website] My computer no longer works since i put ubuntu on it...
    By computer_expert in forum Jokes/Interweb Things
    Replies: 15
    Last Post: 14th July 2010, 11:55 PM
  2. IE7 runonce homepage
    By RabbieBurns in forum Windows
    Replies: 14
    Last Post: 14th November 2009, 07:13 AM
  3. [Website] How It Works .... The Computer (Ladybird books, 1978) with new material
    By Little-Miss in forum Jokes/Interweb Things
    Replies: 11
    Last Post: 12th July 2009, 08:19 PM
  4. Replies: 11
    Last Post: 6th June 2008, 12:34 PM
  5. Computer Startup Scripts
    By Spot in forum Windows
    Replies: 18
    Last Post: 16th November 2005, 11:06 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •