简体   繁体   English

如何使用批处理文件停止和重新启动音频服务?

[英]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.

相关问题 使用批处理文件重新启动远程tomcat来停止手动干预以重新启动? - Restart remote tomcat using batch file to stop manual intervention to restart? 使用批处理文件重新启动远程 Windows 服务 - Restart a remote windows service using batch file 如何通过单击 JMenuItem 执行批处理文件以在 Windows 上重新启动服务? - How to execute a batch file to restart a service on windows by clicking a JMenuItem? 试图杀死Windows服务,然后使用批处理文件重新启动它 - Trying to kill a windows service and then restart it with a batch file 批处理文件读取值后重新启动服务 - Batch File to restart the service after reading value 使用带有c#的批处理文件停止Windows服务 - Stop windows service using batch file with c# 如何通过批处理文件检查服务是否正在运行,如果服务未运行则停止服务? - How to check if a service is running via batch file and stop it if it is not running? 使用其他批处理文件停止批处理文件? - Stop a batch file using another batch file? 批处理文件停止服务共18个然后删除文件然后重新启动服务 - Batch file to stop services 18 in total then delete files and then restart services Windows服务的批处理文件停止,存档日志并重新启动服务 - Batch file for Windows services stop, archive logs and restart the services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM