Link to home
Start Free TrialLog in
Avatar of bryant_buckland
bryant_buckland

asked on

How to force a reboot based on uptime

Hello,

Has anyone found a way to force a laptop or desktop Windows-based computer (XP, 7) to reboot after a period of time.  For example, I would like to implement something that works like this: If the system is up for X amount of days, a message comes up telling the user he needs to reboot based on the policy.  Roughly 66% of our workforce is using laptops and I'm sure a lot of them are simply hibernating nightly instead of rebooting.  This has caused some problems with software we push that require reboots.  Has anyone does anything similar to this?  I'm sure the other option is to disable the hibernate and log off buttons using group policy but I want to try to avoid that at the moment.
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of G3m1n1
G3m1n1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bryant_buckland
bryant_buckland

ASKER

That script looks interesting, but I think I see an issue with it.  We have a lot of users who work nights and weekends for system maintenance purposes.  Unless I'm reading it wrong, it looks like the script will reboot the machine if the user is actively logged in.  Have you implemented this in production, Gem1n1?
I noticed that as well.  I think a little modification in the reboot subroutine to generate a pop-up prompt would solve that issue.

I have not implemented this exact script in production because we use group policy, WSUS, and SCCM to enforce reboots after important updates.  My company is all laptops for everyone so we had to come up with a more detailed solution.
Alright, thanks G3m1n1.  I was hoping for more of a supported or Group Policy solution, but I think this will work.  I'll take your script, modify it and make it work for our environment.  Thanks for your help!
I gave it a B only because the solution wouldn't work for us as-is.  It'll require modification of the code to make sure logged in users don't get booted off.
Tried this script and get an error at line 121 about a variable not being set (see first attachment). I comment out the line and run it again to get a message "privilege not held" (2nd attachement). Tried letting task scheduler run it with "highest privilege" but same messages come up. The account I login with does have administrator rights.

What am I missing?
restartscript-err1.jpg
restartscript-err2.jpg