Batch File Help

Hi-

I'm trying to create a batch file to restart ehtray.exe (ehtray is a application in Windows XP Media Center that is used for the actual media center portion of the OS and as the on screen volume indicator - the green bars). I'm trying to create the batch file, because when I unplug my external speakers (I have a laptop), the volume indicator gets messed up. When I restart ehtray.exe in Process Explorer, the problem is fixed. It would be easier to press a hotkey and have the problem fixed with a batch file or have the batch file run automatically when the external speakers are unplugged or plugged in.

Sadly, I do not know how to write a batch file that restarts a program or if I can have the batch file run when the external speakers are unplugged or plugged in. Can anyone help me out?

You should be able do it either via a batch file by inserting the path to the file name, or via a standard shortcut.

Batch File example:

  1. Open Notepad.
  2. Type in (this is just an example):
    "C:\Windows\System32\ehtray.exe"
    
     cls
    
     exit
    
  3. Save the batch file as (example, include the quotes so you don't save as a text document):
    "Launch ehtray.bat"
    

With a batch file running in WinXP it typically stays open until a program it launched is closed, hence the reason to use a standard shortcut which doesn't have that behaviour.

Thanks for the suggestion. Unfortunately, it didn't work. Maybe I did something stupid. This is my batch file:

"C:\WINDOWS\ehome\ehtray.exe"

cls

exit

I saved it as "Launch ehtray.bat", yet it doesn't work. It is a bat file, not a notepad document.

I don't know which version of Windows you have therefore the below suggestion may not work.

If that file is a service you may be able to launch it via:

Start -> Run -> services.msc

1. That is XP MCE.

2. It is not a service.

3. If I am understanding ThatDude correctly, ehtray.exe needs to be killed then restarted.

So try this:

taskkill /im ehtray.exe /Fstart C:\WINDOWS\ehome\ehtray.execlsexit

The first line kills the running ehtray.exe, the second restarts ehtray.exe

cls and exit are not actually needed, but they make the command window close slightly faster.

Hopefully this is what you needed! B)

1. That is XP MCE.

2. It is not a service.

3. If I am understanding ThatDude correctly, ehtray.exe needs to be killed then restarted.

So try this:

taskkill /im ehtray.exe /Fstart C:\WINDOWS\ehome\ehtray.execlsexit

The first line kills the running ehtray.exe, the second restarts ehtray.exe

cls and exit are not actually needed, but they make the command window close slightly faster.

Hopefully this is what you needed! B)

That is exactly what I needed! Thank-you very much! Just out of curiosity, would I be able to make this batch file run automatically whenever the Sound Playback device changes? Also, I tried modified it so that Winamp is restarted if it is running, but it doesn't work.

Here's the code:

taskkill /im ehtray.exe /Fstart C:\WINDOWS\ehome\ehtray.exetasklist | find "winamp.exe" > nul | (taskkill /im winamp.exe /Fstart "C:\Program Files\Winamp\winamp.exe")clsexit

Any ideas? Thanks again!

1. Not easily possible to run on sound device change.

Maybe with more advanced scripting, but definitely not with a batch file.

2. This *should* work with your Winamp problem:

taskkill /im ehtray.exe /Fstart C:\WINDOWS\ehome\ehtray.exetaskkill /im "winamp.exe"if %errorlevel%==0 (start /d "C:\Program Files\Winamp" winamp.exe)clsexit

Line 3: closes WinAmp, and sets the ERRORLEVEL to 0 if it closed properly.

Line 4: Checks for the correct ERRORLEVEL, then changes to the Winamp folder and starts it.

This will start winamp only if it was running in the first place.

Any other questions, feel free to ask! B)

1. Not easily possible to run on sound device change.

Maybe with more advanced scripting, but definitely not with a batch file.

2. This *should* work with your Winamp problem:

taskkill /im ehtray.exe /Fstart C:\WINDOWS\ehome\ehtray.exetaskkill /im "winamp.exe"if %errorlevel%==0 (start /d "C:\Program Files\Winamp" winamp.exe)clsexit

Line 3: closes WinAmp, and sets the ERRORLEVEL to 0 if it closed properly.

Line 4: Checks for the correct ERRORLEVEL, then changes to the Winamp folder and starts it.

This will start winamp only if it was running in the first place.

Any other questions, feel free to ask! B)

Thanks for your speedy reply! At first the code didn't restart Winamp, but then I added /F after line three of your code (to force Winamp to close) and everything is working now.

Anyway, I have a few questions/thoughts:

  1. Would the advanced script version of this code with the automatic run on a sound device change be hard to code? What programming language would be used? I took a C++ course and a Java course in high school about a year or two ago. (Never wrote a batch file, though)

  2. I would like Winamp to resume playing the track at the time it left off at when the batch file runs when Winamp restarts. Winamp has a hotkey "Ctrl + J" that is used to jump to a time in the track. It brings up a window that shows the current time in a text box. Would I be able to create a variable that could save the time and then place that value in the time in the text box? I can also create a global hotkey in Winamp's preferences that does the same function so that Winamp would not have to be the active window for the hotkey (Ctrl + J) to work.

  3. When Winamp is forcefully restarted the current song playing is not the song that is active when Winamp starts again. I would also need to save the song title and artist to a variable. In order to do so, I would need to distinguish among different text boxes in a single window.

Thank-you so much for all your help!

I suggest you look into languages that are geared more toward scripting.

AutoIt is free, and it is very versatile, most people can get quite far just by looking through the AutoIt forums. The forum experts there could help you with just about any AutoIt question you could ever possibly have.

I am not much of a programmer, so this is where my wealth of knowledge ends. :lol:

I suggest you look into languages that are geared more toward scripting.

AutoIt is free, and it is very versatile, most people can get quite far just by looking through the AutoIt forums. The forum experts there could help you with just about any AutoIt question you could ever possibly have.

I am not much of a programmer, so this is where my wealth of knowledge ends. :lol:

AutoIt looks pretty cool! Thanks for the suggestion. I'll definitely look into it. Thanks again for all your help!

Heya I know this is a old post but hey thought I'd give it a shot.

I'm trying to create a batch file that plays a file in winamp on a double click like normal but queues the next file if the first is still playing. I've already created one that checks to see if winamp is open and if it isn't opens it and plays the file and if it is queues the file. This works ok but what I'm after really is some way of telling if winamp is playing a file. I'm using xp pro sp3. Any help would be most appreciated thanks

You should create a new thread for that :)

If there is a way to do that, I think the Winamp forum will be more helpful...this is the kind of thing that has to be built into Winamp.