batch - How can I make the computer beep from a script/program called by the Windows task scheduler?

06
2013-12
  • gorcq

    I am using Windows 7 home edition. I want to make my computer wait a certain amount of time, then beep in warning right before it terminates a program. As a test, I wrote the following batch file to make Windows Media Player play the radio, wait 10 seconds, then beep and turn it off:

    @echo off
    start "_" "C:\Program Files (x86)\Windows Media Player\wmplayer.exe" "http://www.cpr.org/content_category_templates/listenTemplate/listenClassical48.asx"
    sleep 10
    @echo ^G
    @echo ^G
    @echo ^G
    @echo ^G
    taskkill /im wmplayer.exe /f
    

    Note: following instructions I found in another question on this site, the "^G" thingy is the character you get when you type control + G at a command prompt. It does not seem to appear on this site, so I replaced it with ^G.

    This worked perfectly. Until, that is, I attempted to make it run automatically using the Windows Task Scheduler. I tried this several times an it did not beep. The other functions worked fine, but no beep was audible.

    The script did not run in a window when started by the task scheduler, and I concluded that this must cause problems with the echo command (nothing to echo to). So, after spending some time searching for a method of causing the beep that did not involve echo, I eventually rewrote the whole thing in the form of a VB .NET console program:

    Imports System.Threading
    
    Module Beep
    
        Sub Main()
            Dim wmp As New System.Diagnostics.Process
            wmp.StartInfo.FileName = "C:\Program Files (x86)\Windows Media Player\wmplayer.exe"
            wmp.StartInfo.Arguments = "http://www.cpr.org/content_category_templates/listenTemplate/listenClassical48.asx"
            wmp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            wmp.Start()
            Thread.Sleep(New TimeSpan(0, 0, 10))
            Console.Beep()
            Console.Beep()
            Console.Beep()
            Console.Beep()
            wmp.Kill()
        End Sub
    
    End Module
    

    This works the same way — including the fact that it only beeps when called manually. When called from the task scheduler, it also fails to beep. I'm not sure what else to try, here. Any help would be appreciated.

  • Answers
  • nhinkle

    It's possible that there's a problem with trying to launch the media player system from a script. You can create a batch script with the Ctrl+G character as you mentioned, and it will use the system beep. I don't think the Ctrl+C method you were talking about actually works.

    Open a command prompt, change directories to where you want to save the batch file, and type the following commands:

    copy con beep.cmd
    

    Ctrl+G, Ctrl+Z

    Now, if you run beep.cmd, it should use the system beep.

    I created a system task to run this batch file, and when I run the task manually, the command window appears and beeps, then exits.

    The way this works is that it copies whatever you type in the command window into the specified file, in this case beep.cmd. You can't just put in ^G in the file, even though that's what appears on screen, because typing that is really just typing ^ and G, while ^G is actually a representation of a different ASCII character altogether. By using the command window method, you can save the actual keypress into the file. You can then edit the batch file if you want it to do other things, just make sure to preserve the line with the special character. It will probably just look like an empty box in notepad.

  • Randolf Richardson

    Look for an option in your Task Scheduler in your Scheduled Task's properties called [something along the lines of] "interact with user" or "interactive" (or something like that). It should be a checkbox, and if you turn it on then it should cause your task to appear in the GUI as well as the audio system.

    Failing that, Steve Gibson's (the creator of the famous SpinRite disk repair utility) has a freeware command-line tool called "Wizmo" which can play a .wav file from a batch file:

      Wizmo (no installation required - this is a stand-alone tool)
      http://www.grc.com/wizmo/wizmo.htm

    I'm hoping that this can do the job for you as well (if it does, then you'll obviously need to record a beep sound in a .wav file).


  • Related Question

    Windows: How to turn off all the beep sounds?
  • Ashwin

    I have set the Windows sound scheme to No Sounds and I still hear some beeps on certain actions. Is there a way to turn off these beeps too?


  • Related Answers
  • tjrobinson

    I've found this blog post which suggests:

    Start > Run > sc stop beep && sc config beep start=disabled
    

    I couldn't test it myself but it should stop the beep and also disable the beep service permanently (or at least until you re-enable it), so there's no need to run it every time or set up a .bat file.

  • John T

    For a GUI approach:

    Start -> Run -> devmgmt.msc [Enter] -> View -> Show hidden Devices.

    then in the window:

    Non-Plug and Play Drivers -> Beep -> Disable.

    There is also the option here to keep it like this permanently when you restart, which I think the net command will not do.

  • fretje

    start -> run -> net stop beep

  • tjrobinson

    If you're on Windows XP you can use TweakUI:

    1. General
    2. Settings
    3. Uncheck: Beep on errors
  • CrimsoИ

    If you're on vista, open the Volume Mixer Dialogue box in the bottom right corner of the start bar and set Windows Sounds to Mute. You have to right-click it and manually select Volume Mixer as opposed to double clicking the speaker.

  • Nicholas Flynt

    I actually had an issue where beeps were coming from my keyboard and my media keys, in particular the mute button played a short beep, kind of defeating the purpose when I wanted to shut my PC up.

    I looked everywhere for a solution, and finally stumbled across the option when I was tinkering around with my bios settings, where there was a simple option to turn off keyboard beeps. Make sure to check there if the OS options are being ignored, especially on a notebook or other PC without an internal PC speaker.

  • Mokubai

    From Annoyances.org

    I have found the easiest way to turn off the annoying system beep in Windows XP when adjusting the volume, is to use method 3, as suggested by fester here

    By following the following steps, you can turn off the beep without having to reboot.

    The steps are;

    1. Right-click on My Computer
    2. On the Hardware tab, click on [Device Manager]
    3. On the "View" menu, select "Show hidden devices"
    4. Under "Non-Plug and Play Drivers", right-click "Beep"
    5. Click "Disable"
    6. Answer [Yes] when asked if you really want to disable it
    7. Answer [No] when asked if you want to reboot
    8. Right-click "Beep" again.
    9. Click "Properties"
    10. On the "Driver" tab, set the Startup type to Disabled
    11. Click [Stop]
    12. Click [OK]
    13. Answer [No] when asked if you want to reboot