Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a windows program deployed using WPKG that runs hidden to the user, and may need to reboot sometimes. In order to prevent the user from losing work, I would like a dialog box with a message, giving the logged in user the option to delay the shutdown for a bit. This is something similar to the way Automatic Update does it.

I've looked at a multitude of shutdown utilities which give the user a message, but none which give them a little control to delay the shutdown.

share|improve this question
    
Ahh! you've changed the question! –  Nick Kavadias Oct 8 '09 at 1:35
    
Ya, specifically, I would like the logged in user sitting at the pc to delay it –  menko Oct 8 '09 at 1:39

2 Answers 2

up vote 3 down vote accepted

A quick and dirty option would be to use PSSHUTDOWN in the PSTOOLS suite from Microsofts Sysinternals.

One of the switches available is -c. It allows the user to stop the reboot by pressing the Cancel button.

-c Allows the shutdown to be aborted by the interactive user.

You could set this to loop every X minutes until the user is ready to have their machine rebooted.


A neater way to do this would be to write your own VBscript. This could provide a snazzy dialog box offering, for example, Yes and No. If they clicked No, it would sleep for X minutes before asking again. This would be very easy to write.

Edit: Well, I was bored so I made the script for you. Enjoy.

option explicit
on error resume next

Dim strComputer, intRebootChoice
Dim objWMIService, objOperatingSystem
Dim colOperatingSystems 

strComputer = "."

do while 1>0
 intRebootChoice = msgbox("OI, you, need to reboot.  Choose No to be asked again 1 hour",308,"Reboot incoming")
 select case intRebootChoice
  case 6
   Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
   Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
   For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Reboot(1)
   Next
  case 7
   wscript.sleep(3600000)
  case else
   'shenanigans'
 end select
loop
share|improve this answer
    
Edit: Added the VBScript –  Izzy Oct 8 '09 at 3:19
    
Thanks, I would up you have I had the rep –  menko Oct 8 '09 at 4:49
    
So long as it helped! –  Izzy Oct 8 '09 at 5:53

the C:\WINDOWS\system32\shutdown.exe utility seems to do the job for me.]

try the following: shutdown -r -t 500 -c "happy user message"

EDIT: The automatic updates reboot message is more of a nag screen with a time-out that has a reboot button. Easy enough to duplicate the code for this, although you may need to ask this on stackoverflow :)

share|improve this answer
    
Yes, the reason why I would like this is that giving a fixed timeout seems a bit forceful. The user may need to wait for something to complete. –  menko Oct 8 '09 at 1:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.