@echo off ::GetServiceAccount.bat ::Jeffery Hicks :: http://jdhitsolutions.com/blog :: http://twitter.com/jeffhicks ::USAGE GetServiceAccount [computername] ::You must run this with an account that has admin rights on any remote computer if %1$==$ ( set zcomp=%Computername% ) else ( set zcomp=%1 ) echo Finding non system service accounts on %zcomp% rem get a list of service names sc \\%zcomp% query type= service state= all | findstr /i "Service_Name" > %temp%\~zlist.qqq for /f "tokens=2* delims=: " %%i in (%temp%\~zlist.qqq) Do if %%j$==$ (Call :Check %zcomp% %%i) else ( Call :Check %zcomp% "%%i %%j") goto :Exit :Check rem echo %2 rem create a temp file sc \\%1 qc %2 | findstr /i "Name" > %temp%\~foo.qqq rem define a counter set zcount=0 rem test for service account name findstr /i "service_start_name" %temp%\~foo.qqq | findstr /i /r "\ NUL if errorlevel 1 set /a zcount+=1 findstr /i "service_start_name" %temp%\~foo.qqq | findstr /i /r "\ NUL if errorlevel 1 set /a zcount+=1 rem If neither type of entry was found then display the temp file if %zcount% equ 2 type %temp%\~foo.qqq :Exit set zcomp= set zcount= rem delete temp file if it still exists if Exist %temp%\~foo.qqq del %temp%\~foo.qqq if Exist %temp%\~zlist.qqq del %temp%\~zlist.qqq