Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   Dev Hardware ForumsSOFTWAREProgramming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Hardware Forums Sponsor:
  Trader Rating: 0 · #1  
Old March 27th, 2008, 02:22 AM
arod arod is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 9 arod User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 5 m 56 sec
Reputation Power: 0
DOS Batch - Play sounds at different time increments

I'm trying to create a batch file that will play a bunch of different sounds at different time increments.

Ideally this batch program will run from startup, and run for a few hours with sounds every so often, and then close. The user will not know that the batch program is running. This will be run in Windows XP.

From what i have found so far, I need to use the command
start /w /m sndrec32.exe /play /close %1
to run the sound recorder. It does not appear that this can be done using WMP.

Can anyone give me any help as to how I can add time increments into the code and how to reference it to each sound file.

Thanks, much appreciated.

Reply With Quote
  Trader Rating: 4 · #2  
Old March 27th, 2008, 03:06 AM
madhyena's Avatar
madhyena madhyena is offline
SץsAםмιи & Wяιτєя
Dev Hardware Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2004
Location: Romania, the one and only.
Posts: 4,566 madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)madhyena User rank is General 87th Grade (Above 100000 Reputation Level)  Folding Points: 65608 Folding Title: Intermediate FolderFolding Points: 65608 Folding Title: Intermediate FolderFolding Points: 65608 Folding Title: Intermediate FolderFolding Points: 65608 Folding Title: Intermediate Folder
Time spent in forums: 1 Year 1 Month 3 Weeks 1 Day 15 h 42 m 9 sec
Reputation Power: 6786
Send a message via AIM to madhyena Send a message via Yahoo to madhyena Send a message via Google Talk to madhyena
Hey there, arod,

Welcome to our forums.

Programming batch files can be pretty neat when using for run-of-the-mill administrative tasks that would be either boring or too much to handle manually on a day-to-day basis. You pop up notepad, write your batch script that does what you were supposed to do, and then run it - voila.

However, in your situation I sense that you are trying to code a slightly complex or rather complex application. I'm sure it can be done with batch and you should focus on how to invoke delays. A rather foolproof method do implement delays in a batch files is using ping time-outs. Sure, this sounds like insane and that it has nothing to do with it. However, the script must stop and ping the specified address (which should not exist) for the amount of time you specified without any output at all and then it moves on. You see, this is a rather simple and naive way to workaround a simple delay.
Batch Code:
Original - Batch Code
    PING 1.1.1.1 -n 1 -w %1000 >NULL
The -n specifies the count of ping requests (1) while the -w explicitly states the number of wait time for each request (1000 ms = 1 second). NULL, as always, sets the output for the ping requests (technicall, NoWhereLand).

Now to be on topic, I would advice writing your "application" in WSH. On the long-run you will be glad that you did. Sure, like I said, at first batch files look promising and quick solutions and we still should use them when we need to automate everyday administrative and/or boring tasks. But in your case you are planning to create a pretty neat utility that should run for hours or so I have understood.

You have picked Sound Recorder and indeed that's what I would also too. It is also more light-weight and definitely faster/quicker/more efficient than WMP is/was/will be. There's no real need to involve WMP in this task. So, here's how I would do this in WSH.
VB Code:
Original - VB Code
  1. strSoundFile = "C:\Temp\test.wav"
  2. Set objShell = CreateObject("Wscript.Shell")
  3. strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
  4. objShell.Run strCommand, 0, True
  5. Wscript.Sleep 1000
The first line declares the variable. The second line of the code sets to create a new object shell which is going to be the Sound Recorder. The third line executes and specifies the parameters for sndrec32. In this case we also set them to play the file, automatically close at the end, and we use a trickier approach to insert the necessary double quotes in order to specify the exact path of the sound file. Char 34 stands for double quotes ("). The fourth line of code runs the object where 0 is the parameter that explicitly specifies the script to be executed in hidden window, while the latter True stands for "wait until the sound file hasn't finished playing" - you need to use False each time you want to move on and execute further commands without waiting out the end of the audio file. Like when you want a message box to appear right away as your audio file is played (Ding! Error Box!). You need to do both at the same time, thus, you need to use False in order to execute the error msgbox command too [like Msgbox "Oh God, error!"]. The final line of the code is very straightforward and puts the script on sleep (delay).

Hope it helps. You can use the same approach as presented above to reference to the audio files even with batch. But I still suggest moving over to WSH for the flexibility that it rather offers. Batch was all neat and cool in the 90s. Now it's all outdated and, to be honest, I haven't used it for my tasks since ages. If we think about it, batch is not even a programming language, it's just a scripting language that is based totally on DOS commands. Whereafter, WSH is a full-throttled and offers access/possilities to fully maintain and code lots of Microsoft-administration and -tedious tasks such as anything from sending mails (or even creating a mass-mailer) up to log parsing and whatnot.

For more information and as a reference source on WSH - I would advice reading the article published by my very best friend - Robert "Nilpo" Dunham. Find his profile(s) over ASP Free and check out some of his WSH material/content; I'm linking both of his profiles because he's special and has two: Nilpo as a Staff Writer and Just Nilpo. He's written a lot on the subject (more than a few dozens of tutorials!).

Cheers. If you have more questions or whatnot, please, don't hesitate to post. I might leave a PM to him if we both need assistance/help in order to accomplish your task. Because if we do that, then the guru will come and enlighten us.
__________________

“Greatness, combined with the hint of a 24-carat lifestyle, is within us striving to make it through, craving for attention,
and in the end, recognition, leaving a record worthy of biography on forging success stories.”
—ME

Check out MadHyeNa's Website & Article Index. Visit Nilpo.com - Ask the Windows Guru!™
I succeed, conquer, and achieve, therefore I am.

Reply With Quote
  Trader Rating: 0 · #3  
Old March 27th, 2008, 04:57 AM
arod arod is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 9 arod User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 5 m 56 sec
Reputation Power: 0
Thanks so much for you reply madhyena, that was a massive help.
I had actually done a bit more research since my post and found that VBScript was going to serve my purposes better as well!

Unfortunately I have almost no experience in VB, but that's ok.

The reason I'm doing this is actually for an April Fool's joke on a friend-I would like the computer to play random sounds at various times thoughout the day!

I plan to put the script into the startup folder, which I am assuming will be executed on startup. The first issue I have is that I am seeing this friend on Sunday, and with April's Fool's day on Tuesday, I obviously don't want the code to execute on Monday when she starts up her computer.
Ss there some way I can make the code so it only executes on 01/04/08, instead of everytime the computer starts up?

Secondly, the time delays are in milliseconds I assume? Is there some way that instead of having a nominal time delay that I can actually get each sound to execute at a specific time throughout the day? ie. one sound at 9:00am, the next at 9:45 etc?

That's all the questions I have for now. If anyone has any ideas to add to what I'm planning it would be much appreciated!
Thanks

Reply With Quote
  Trader Rating: 1 · #4  
Old March 27th, 2008, 10:29 AM
weevilofdoom's Avatar
weevilofdoom weevilofdoom is offline
BLURG
Dev Hardware Loyal (3000 - 3499 posts)
 
Join Date: Sep 2004
Location: Oregon
Posts: 3,420 weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)weevilofdoom User rank is General 37th Grade (Above 100000 Reputation Level)  Folding Points: 32443 Folding Title: Starter FolderFolding Points: 32443 Folding Title: Starter Folder
Time spent in forums: 2 Months 23 h 55 m 21 sec
Reputation Power: 3411
Send a message via ICQ to weevilofdoom Send a message via AIM to weevilofdoom Send a message via MSN to weevilofdoom Send a message via Yahoo to weevilofdoom Send a message via Google Talk to weevilofdoom
use the windows scheduled tasks in the control panel - this will suit this perfectly. Don't worry about time so much in your app, but schedule it to run for 24 hours only - every 45 minutes. You're golden!!
__________________

Reply With Quote
  Trader Rating: 0 · #5  
Old March 30th, 2008, 02:20 AM
arod arod is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 9 arod User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 5 m 56 sec
Reputation Power: 0
In regards to using a message box, I'm currently including the line for this between lines 4 and 5.

When I do this, the delay doesn't begin counting until I click 'Ok' on the message box.
Is it possible to make it that the delay starts counting as soon as the message box comes up?

Thanks

Reply With Quote
Reply

Viewing: Dev Hardware ForumsSOFTWAREProgramming > DOS Batch - Play sounds at different time increments


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway