0Day Forums
How to stop and restart Audio Service using a batch file? - Printable Version

+- 0Day Forums (https://zeroday.vip)
+-- Forum: Coding (https://zeroday.vip/Forum-Coding)
+--- Forum: .bat & .wsf & .cmd (https://zeroday.vip/Forum-bat-wsf-cmd)
+--- Thread: How to stop and restart Audio Service using a batch file? (/Thread-How-to-stop-and-restart-Audio-Service-using-a-batch-file)



How to stop and restart Audio Service using a batch file? - anal363 - 07-23-2023

I made a batch file with the following line

net stop audiosrv & net start audiosrv

It just flashes and closes, not actually doing the command. I think I saw something about administrator privileges in the command window but it flashed too fast to tell. What is wrong?


RE: How to stop and restart Audio Service using a batch file? - gar781879 - 07-23-2023

The audio service is started by Windows using local system account and therefore it is not possible to stop this service without administrator privileges as command `net` outputs.

The solution is clicking with right (secondary) mouse button on batch file and click with left (primary) mouse button in context menu on **Run as Administrator** as [Magoo](

[To see links please register here]

) already suggested before.

For testing a batch file just created, it is always useful to open a command prompt window and run the batch file from within this window by entering name (with path if needed) and hitting RETURN. A shortcut for opening a command prompt window can be found in Accessories menu of Windows start menu, or the command `cmd.exe` is executed which also opens a console window.


RE: How to stop and restart Audio Service using a batch file? - orianna475 - 07-23-2023

Create a new text file.
Then, paste the following code into it.

@echo off
net stop audiosrv
pause
net start audiosrv
pause

Save the file as a bat file.
Open the bat file as admin.



RE: How to stop and restart Audio Service using a batch file? - nymphalids2468 - 07-23-2023

Here find a script for running a batch file as an admin
```
@echo off

if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
net stop audiosrv
pause
net start audiosrv
pause
```


RE: How to stop and restart Audio Service using a batch file? - bsez - 07-23-2023

A more comprehensive batch file approach:

@echo off

if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
net stop audiosrv
pause
net stop AudioEndpointBuilder
pause
net start AudioEndpointBuilder
pause
net start audiosrv
pause