도메인내의 여러 컴퓨터에서 DomainName/UserName 환경으로 기동하는 서비스가 존재한다면 DomainName/UserName을 다시 설정하는 것은 상당히 지루한 일일 것이다.
리소스 킷의 NETSVC와 SC를 사용하고 다음 배치파일을 경로내에 둠으로서 이러한 과정을 모두 자동화할 수 있다.
SetSvcPw.bat
@echo off
@echo SetSvcPw %1 %2 %3
if exist %1 goto OK
:bad
@echo Syntax: SetSvcPw "\ComputerName.txt" DomainName\UserName 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%\netsvc.log
for /f %%s in (%TEMP%\netsvc.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
이 파일을 실행하고 결과를 기록하기 위해 다음과 같이 입력한다.
SetSvcPw "\ComputerName.txt" DomainName\UserName password
"\SetSvcPw.log" 2&1
여기서 "\ComputerName.txt"는 도메인 내의 컴퓨터의 이름 목록(도메인 구성원의 컴퓨터 이름 목록 생성하기을 본다)을 포함한다.
"\ComputerName.txt"의 형식은 다음과 같다.
ComputerName1
ComputerName2
. . . . . . . . . . . .
ComputerNamen
댓글: