Sunday, May 13, 2018

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

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.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...