[英]How to stop and restart Audio Service using a batch file?
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?
怎么了?
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.将文件另存为 bat 文件。 Open the bat file as admin.
以管理员身份打开bat文件。
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
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
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.音频服务由 Windows 使用本地系统帐户启动,因此如果没有管理员权限作为命令
net
输出,则无法停止此服务。
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 already suggested before.解决方案是在批处理文件上单击鼠标右键(辅助),然后在以管理员身份运行的上下文菜单中单击鼠标左键(主) ,因为之前已经建议过Magoo 。
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.可以在 Windows 开始菜单的附件菜单中找到打开命令提示窗口的快捷方式,或者执行命令
cmd.exe
也会打开控制台窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.