I have attempted to write some code to do this, but have fallen short of actually being successful.
I wonder if this is because of permission issues? Although, running the file in admin CMD doesn't make a difference.
Could it be that ECHO is somehow reset to on during the function calls?
Here's the code:
[code]
@echo off
cls
echo.
echo Hello, %username%.
echo This program will enable the sound service.
echo.
:case_1
call:print "Attempting to start Windows Audio..."
call:check_audio "sc start AudioSrv" "case_2"
:case_2
call:print "Attempting to start Windows Audio again..."
call:check_audio "C:\Windows\System32\svchost.exe -k LocalServiceNetworkRestricted" "case_3"
:case_3
echo.
echo Attempting to start dependencies...
echo.
call:print "Starting Multimedia Class Scheduler..."
call:check_active "MMCSS" "sc start MMCSS" "case_4" "Multimedia Class Scheduler"
call:print "Starting Remote Procedure Call (RPC)..."
call:check_active "RpcSs" "sc start RpcSs" "case_4" "Remote Procedure Call (RPC)"
call:print "Starting Windows Audio Endpoint Builder..."
call:check_active "AudioEndpointBuilder" "sc start AudioEndpointBuilder" "case_4" "Windows Audio Endpoint Builder"
call:print "Attempting to start Windows Audio again..."
call:check_audio "sc start AudioSrv" "case_4"
:case_4
echo.
echo Attempting to start dependencies again...
echo.
call:print "Starting Multimedia Class Scheduler..."
call:check_active "MMCSS" "C:\Windows\system32\svchost.exe -k netsvcs" "error" "Multimedia Class Scheduler"
call:print "Starting Remote Procedure Call (RPC)..."
call:check_active "RpcSs" "C:\Windows\system32\svchost.exe -k rpcss" "error" "Remote Procedure Call (RPC)"
call:print "Starting Windows Audio Endpoint Builder..."
call:check_active "AudioEndpointBuilder" "C:\Windows\System32\svchost.exe -k LocalSystemNetworkRestricted" "error" "Windows Audio Endpoint Builder"
call:print "Attempting to start Windows Audio again..."
call:check_audio "C:\Windows\System32\svchost.exe -k LocalServiceNetworkRestricted" "error"
:print
echo %~1
echo.
:check_audio
:: Checking if Windows Audio is active. If it is unable to be activated, GOTO <label>.
:: If it has already been activated, GOTO exit.
for /f "tokens=3 delims=: " %%H in ('sc query "AudioSrv" ^| findstr " STATE"') do (
if /i "%%H" NEQ "RUNNING" (
:: Tokenises line containing service's state, pulls out third token.
:: Tests resulting state against the string, "RUNNING".
%~1 || goto %~2
) else (
goto quit
)
)
:check_active
:: Checking if service is active. If it is unable to be activated, GOTO <label>.
:: If it has already been activated, state that it is already running.
for /f "tokens=3 delims=: " %%H in ('sc query "%~1" ^| findstr " STATE"') do (
if /i "%%H" NEQ "RUNNING" (
%~2 || goto %~3
) else (
echo %~4 is already running.
)
)
:error
:: States what error the program failed with and exits.
echo Program failed with error #%errorlevel%.
exit /b %errorlevel%
:quit
echo The program was successful. Windows Audio is running.
echo.
pause
exit
[/code]
After "case_1" is done, I see errors like:
[i]
system cannot find the drive specified.
'Attempting' is not recognised as an internal or external command...
system cannot find the batch label specified -
[SC] StartService FAILED 1068:
The dependency service or group failed to start.
[SC] StartService FAILED 1084:
This service cannot be started in Safe Mode.
[/i]
And this is why it's disabled in safe mode? It doesn't let you re enable it even through batch. Why are you so desperate to have sound in safe mode? The sound is purposely disabled to make the system more stable
Sorry, you need to Log In to post a reply to this thread.