In Windows 7, how do I know when a computer is scheduled to be shutdown?

5

Say I use "shutdown -s -f -t 13600" to initiate a scheduled shutdown.

In Windows XP, I would always see a dialogbox alerting me of the impending shutdown.

In Windows 7 however it shows a popup in the system tray, which disappears after a couple of seconds.

How do I query, or enable a dialog like Windows XP for me to know when the shutdown is going to happen?

KalEl

Posted 2011-07-30T14:17:37.753

Reputation: 1 090

Answers

4

I've found a way.

If instead of using shutdown -s -f -t 13600

you use shutdown -s -f -t 13600 -c "13600"

The -c option adds a comment to the shutdown event logged by Windows Event Viewer

Your comment of "13600" will be visible in the Event Viewer as seen in the red oval: event viewer showing system events

To see this view yourself:type Event Viewer in the start menu and go to Windows Logs -> System and you will see a list of system events.

Any events with an Event ID of 1074 will be a delayed shutdown.

So what we want is some code that gets the last 1074 event, looks up the value in the comment of the event and adds that value (in seconds) to the time the event was created, thus giving the shutdown time.

I made a function for Windows PowerShell (comes with Windows 7) that does that:

function nextShutdownTime
{
    $events = Get-WinEvent -FilterHashtable @{logname="system"; id=1074}
    $event = $events[0]
    $eventXML = [xml]$event.ToXml()
    return $event.TimeCreated.addSeconds([int]$eventXML.Event.EventData.Data[5])
}

Just add it to your PowerShell Profile and in PowerShell just run the command nextShutdownTime to see the expected shutdown time.

Griffin

Posted 2011-07-30T14:17:37.753

Reputation: 323

1

I just spent about an hour trying to make this work exactly as you wanted somehow. I experimented, and searched and searched, but I could not get it perfect, but I was able to come up with something.

I tried every combination of shutdown (-i -c -d options), but nothing.

I also experimented with the GUI interface after the -i option.

I also tried changing the balloon time display so it would stay down in the systray longer, but still, even that disappears.

The closest I go with with this sample command: shutdown -i -r -t 300

I think the fact is that they simply changed the way it works, and I don't think there is any way around it 100%, but the -i now brings up a dialog box, whereas it used to bring up the screen you wanted. When I used the -i in Windows 7, I had to fill out the box, and here was the result:

enter image description here

Then I hit Enter and got this:

enter image description here

I tested, and it seems that the upper value you can put in the "Display warning for X Seconds" is only 600, despite the fact you can enter up to 999 (very strange programming).

KCotreau

Posted 2011-07-30T14:17:37.753

Reputation: 24 985

I just realized that it still does not do the countdown thing either. – KCotreau – 2011-07-30T16:13:43.947

Yeah, the server 2008 shutdown along with the xp shutdown only allow you up to 600 seconds. The windows 7 and 2008R2 allow something like up to 10 years. – surfasb – 2011-07-31T05:16:12.063

1

How do I query, or enable a dialog like Windows XP for me to know when the shutdown is going to happen?

The native shutdown program in Windows 7 does not provide a countdown dialog (or a cancel button) like previous versions of Windows did.

If you need to schedule a shutdown and provide a countdown and cancel button you can use an HTA application, which can have text, images, a countdown and a cancel button.

Here is an example: HTA Script - Shutdown script and warning message

Shutdown dialog

Source is my personal blog.

ovann86

Posted 2011-07-30T14:17:37.753

Reputation: 1 106

0

The easiest way to find out if a shutdown is in progress, is to simply schedule another shutdown. Give it a timeout of at least 200 seconds, just to be sure. Either you get an error stating that there is already a shutdown in progress, or it will initiate a timed shutdown that you can abort by typing shutdown /a.

So you type

shutdown /r /t 600

Now you either get

C:\Users\Administrator>shutdown /r /t 600
A system shutdown has already been scheduled.(1190)

or it will schedule a new shutdown.

If you only want to make sure no shutdown is scheduled, you can simply attempt an abort. Either it will abort, or it will state that no shutdown was scheduled.

C:\Users\Leon>shutdown /a
Cannot abort a system shutdown. There is no shutdown in progress (1116)

LPChip

Posted 2011-07-30T14:17:37.753

Reputation: 42 190