Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When shutting down Windows 7, how to get an app to start up automatically and run briefly then close?

I want the app to briefly show on the screen, or briefly say on the speakers, my reminder-to-self "Unplug USB stick, turn off heater before leaving room". After that, Win 7 shuts down.

share|improve this question
I don't think there's any guarantee the task will complete before it is terminated. – Karan Jun 20 '13 at 17:42

Use a Windows scheduled task to do this. add a trigger "at user logoff" (might be called differently, I'm not on an english windows right now).

If you want to play a sound, you have to record it first, and then run your favourit music player with the recorded sound file as a command line parameter. most players have their command line parameters on their website somewhere, or just google for it.

if you want to show a message, you should use a windows *.bat file.

share|improve this answer
Thanks Steffen and Karan. I tried Scheduler but couldn't find that sort of trigger. – doanviettrung Jun 21 '13 at 11:32

Karan is right: there is no guarantee the task will be able to execute in its entirety. I tested the Group Policy method on my own machine, but with an SSD, a respectable CPU, and 12gb memory, the small audio player I was trying to execute never even got a chance to start!

The complicated solution -- if one exists -- would mean hooking into the shutdown process and temporarily suspending it one way or another, to give your audio file time to load before continuing with the procedure.

A less overkill (appropriatelykill?) solution would mean writing a batch or script file that launches your audio file, possibly with a timer set to correspond to the length of the audio file (plus a little for the audio player program to load into memory), or some other way of determining that the audio process has completed, and then triggering the shutdown process. You would then execute that batch or script file instead of executing shutdown by your usual means (such as via the Start Menu).

Lucky for you, I have taken the time to write just such a script. Save this in a text editor and give it a ".vbs" extension. Assign a shortcut to it and place it in your Start menu or desktop and set it up with an appropriate icon. (Note: I was in a quirky mood when I named my variables and functions, but it works.)

Option Explicit
Dim dudeWeNeedAWindow, beMyWordsYo, whatTheCrapDoWeCallIt, thereOnceWasADefaultNamedOne, imAChooseStuffIsThatAlright, imJustGoingToTellYouRightNowThatWasALowBall, dontMockMeIWasFeatherDustedAsAChild, thisIsWhereThePartyHappensSucka, thisCrapNeedsToShutItselfDown, bringItHonkyIllJustStartAllOverAgain, imSorryButYouNeedToSettleDownAndHibernateRightNow

beMyWordsYo = "How would you like to proceed?" & vbcr & vbcr & _ 
"1) Shutdown" & vbcr & _ 
"2) Restart" & vbcr & _ 
"3) Hibernate"

dontMockMeIWasFeatherDustedAsAChild = "Nonsense! What are you trying to pull?"
thisIsWhereThePartyHappensSucka = """C:\Program Files\MPC-HC\mpc-hc64.exe"" %USERPROFILE%\Music\Vermillion.mp3"

whatTheCrapDoWeCallIt = "Shutdown"
thereOnceWasADefaultNamedOne = "1"

thisCrapNeedsToShutItselfDown = """shutdown.exe"" /s /t 00"
bringItHonkyIllJustStartAllOverAgain = """shutdown.exe"" /r /t 00"
imSorryButYouNeedToSettleDownAndHibernateRightNow = """shutdown.exe"" /h"

Sub ShutdownThisGoober
    imAChooseStuffIsThatAlright = InputBox(beMyWordsYo,whatTheCrapDoWeCallIt,thereOnceWasADefaultNamedOne)

    Set dudeWeNeedAWindow = WScript.CreateObject("WScript.Shell")

    If imAChooseStuffIsThatAlright = "1" Then
    ElseIf imAChooseStuffIsThatAlright = "2" Then
    ElseIf imAChooseStuffIsThatAlright = "3" Then
    ElseIf imAChooseStuffIsThatAlright = "0" Or imAChooseStuffIsThatAlright = "" Then
        imJustGoingToTellYouRightNowThatWasALowBall = MsgBox(dontMockMeIWasFeatherDustedAsAChild,16)
        Set dudeWeNeedAWindow = Nothing
    End If
    Set dudeWeNeedAWindow = Nothing
End Sub
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .