@echo off
set SQLSERVICE_USERNAME=sqluser
set SQLSERVICE_PASSWORD=sqluser@123
setlocal
for /f "tokens=*" %%a in ('sc query type^= service state^= all^|find "MSSQL$"') do set SQL_SERVICE_NAME=%%a
for /f "tokens=*" %%a in ('sc query type^= service state^= all^|find "SQLAgent$"') do set SQL_AGENT_SERVICE_NAME=%%a
SET SQL_SERVICE_NAME=%SQL_SERVICE_NAME:~14%
SET SQL_AGENT_SERVICE_NAME=%SQL_AGENT_SERVICE_NAME:~14%
echo "%SQL_SERVICE_NAME% service changing to the user %SQLSERVICE_USERNAME%"
sc config %SQL_SERVICE_NAME% obj= %SQLSERVICE_USERNAME% password= %SQLSERVICE_PASSWORD%
echo "%SQL_AGENT_SERVICE_NAME% service changing to the user %SQLSERVICE_USERNAME%"
sc config %SQL_AGENT_SERVICE_NAME% obj= %SQLSERVICE_USERNAME% password= %SQLSERVICE_PASSWORD%
net stop %SQL_SERVICE_NAME% /y
net start %SQL_SERVICE_NAME%
net start %SQL_AGENT_SERVICE_NAME%
set SQLSERVICE_USERNAME=sqluser
set SQLSERVICE_PASSWORD=sqluser@123
setlocal
for /f "tokens=*" %%a in ('sc query type^= service state^= all^|find "MSSQL$"') do set SQL_SERVICE_NAME=%%a
for /f "tokens=*" %%a in ('sc query type^= service state^= all^|find "SQLAgent$"') do set SQL_AGENT_SERVICE_NAME=%%a
SET SQL_SERVICE_NAME=%SQL_SERVICE_NAME:~14%
SET SQL_AGENT_SERVICE_NAME=%SQL_AGENT_SERVICE_NAME:~14%
echo "%SQL_SERVICE_NAME% service changing to the user %SQLSERVICE_USERNAME%"
sc config %SQL_SERVICE_NAME% obj= %SQLSERVICE_USERNAME% password= %SQLSERVICE_PASSWORD%
echo "%SQL_AGENT_SERVICE_NAME% service changing to the user %SQLSERVICE_USERNAME%"
sc config %SQL_AGENT_SERVICE_NAME% obj= %SQLSERVICE_USERNAME% password= %SQLSERVICE_PASSWORD%
net stop %SQL_SERVICE_NAME% /y
net start %SQL_SERVICE_NAME%
net start %SQL_AGENT_SERVICE_NAME%