1.

Solve : Simple Batch File Help!?

Answer»

Hi..   I've created 2 simple batch files that start and stop "windows audio" service  (as I often need to stop/start it when I'm working with MUSIC and using different drivers)

So far im just using net start/stop "windows audio"

However I was wondering if I could ACHIEVE the same THING just using 1 batch file that uses a conditional statement that effectively turns in on and off i.e

//=============================
If (Windows Audio Service = running)

     net stop "Windows Audio"

Else{
    net start "Windows Audio"
}
//=============================

Is it possible to create a batch file that acts as a switch to turn the service on and off?
Any help is much appreciated.  Code: [Select]echo off
set status=not running
sc query type= service | FIND "AudioSrv" > nul && set status=running
echo The Windows Audio Service is %status%.
if "%status%"=="running" (
net stop "Windows Audio"
) else (
net start "Windows Audio"
)
pause

Output:

Code: [Select]C:\Batch\Test>SwitchWindowsAudioService.bat
The Windows Audio Service is running.
The Windows Audio service is stopping.
The Windows Audio service was stopped successfully.

Press any key to CONTINUE . . .

[64]C:\Batch\Test>SwitchWindowsAudioService.bat
The Windows Audio Service is not running.
The Windows Audio service is starting.
The Windows Audio service was started successfully.

Press any key to continue . . .

[64]C:\Batch\Test>

Quote from: Salmon Trout on March 17, 2012, 02:32:17 AM

Code: [Select]echo off
set status=not running
sc query type= service | find "AudioSrv" > nul && set status=running
echo The Windows Audio Service is %status%.
if "%status%"=="running" (
   net stop "Windows Audio"
) else (
   net start "Windows Audio"
)
pause

Output:

Code: [Select]C:\Batch\Test>SwitchWindowsAudioService.bat
The Windows Audio Service is running.
The Windows Audio service is stopping.
The Windows Audio service was stopped successfully.

Press any key to continue . . .

[64]C:\Batch\Test>SwitchWindowsAudioService.bat
The Windows Audio Service is not running.
The Windows Audio service is starting.
The Windows Audio service was started successfully.

Press any key to continue . . .

[64]C:\Batch\Test>

Fantastic!  Thank you very much for the speedy response, you have made things a lot easier and cleaner for me.


Discussion

No Comment Found