JSI Tip 0691 - How do I reset the password on all services in my domain that run in the ServiceAccount context?

Jerold Schulman

August 30, 1998

1 Min Read
ITPro Today logo

If you have services that run in a DomainName/UserName context on multiple machines in your domain, resetting the DomainName/UserName password can be quite a chore.

To totally automate this process using NETSVC and SC from Supplement 4 of the Resource kit, add the following batch files to your path:

SetSvcPw.bat

@echo off

@echo SetSvcPw %1 %2 %3

if exist %1 goto OK

:bad

@echo Syntax: Error: SetSvcPw "
 
ComputerName.txt" DomainNameUserName password
goto end
:OK
if .%2.
.. goto bad
if .%3.
.. goto bad

for /f %%i in ('type %1') do call :setsvcpws %%i %2 %3

goto end

:setsvcpws

if exist %temp%NETSVC.LOG del /f /q %temp%NETSVC.LOG

for /f "Tokens=1,2* Delims=," %%a in ('netsvc \%1 /list') do echo %%b >> %TEMP%etsvc.log

for /f %%s in (%TEMP%etsvc.log) do call SetSvcPwT %%s %1 %2 %3

if exist %temp%NETSVC.LOG del /f /q %temp%NETSVC.LOG

:end


SetSvcPwT.bat

@echo off
if "%1"
"ECHO" goto end
for /f "Tokens=1,2,3* Delims= " %%i in ('sc \%2 qc %1') do call :user %%k %1 %2 %3 %4
goto end
:user
if /i NOT "%1"
"%4" goto end

echo \%3 %2 %4 %5

sc \%3 stop %2

sleep 4

sc \%3 config %2 obj= %4 password= %5

sc \%3 qc %2

sc \%3 start %2

:end

To run the job and log the results, type:

SetSvcPw " ComputerName.txt" DomainNameUserName password >> " SetSvcPw.log" 2>&1

Where " ComputerName.txt" contains a list of computer names in your domain (see tip 677).
The Format of " ComputerName.txt" is:

ComputerName1
ComputerName2
. . . . . . . . . . . .
ComputerNamen

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like