Question Locked

Reboot at Logoff

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I determine how long a computer has been up since the last reboot. In order to be as non-intrusive as I can, I want to reboot the computer when the user logs off, when it exceeds the amount of time I have specified. As we know, at logoff or shutdown, programs will not run as the computer is in a "logoff" or "shutdown" state and will not allow it. Does anyone know a way around this?

7 replies

by Member 25348569

if you use a GPO. You could have this script check the time since last reboot and force a reboot if necessary.

Neil :)

by john.tompkins2

Thank You for your response.
Yes, I am using a GPO. My script is in the User Policy\User Configuration\Windows Settings\Scripts\Logoff
The script checks for uptime hours and if over the limit runs the shutdown command with a restart.
What happens is, when the user initiates a "logoff" I have it display a window so I can see the script executing....The script runs but it won't execute the shutdown command because windows is in a shutdown (logoff) state, and won't allow an executable to start. Any ideas?

by Member 25348569

I'm assuming you're running vbscript - is that correct? If so, can you force a reboot from within the script using WMI rather than running the shutdown executable? There are four logoff/shutdown option within WMI including a 'force'.

Neil :)

by john.tompkins2

....
Case "forcereboot"
intShutdownType = 6
....
Set colOperatingSystems = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objOperatingSystem In colOperatingSystems
ObjOperatingSystem.Win32Shutdown(6)
Next

This works great interactively, but when run in the logoff scripts from the GPO, it doesn't work.

by Member 25348569

It's not something that I've ever tried. I was hoping that the Force Reboot option in WMI would work but if you've tried that then you are past where I was thinking.

If you really HAVE to reboot the systems then one easy way - but a bit gross - is to run the check for uptime and reboot at log ON. However, it's not my users that it's going to upset.

I'll keep thinking...

Neil ?:|

by john.tompkins2

Yes, we really have to reboot the systems, as we have a "120" hour policy. I have been rebooting at logon time with a nice message that informs our users that they can avoid this inconvenience if they reboot their machines prior to the mandatory reboot.
I am trying to provide a less intrusive mandatory reboot for those that don't comply.
If you happen to find something please let me know, and Thank You for your input.

This discussion is closed to new replies.