Question

first an avowal! i am begginer in batch file scripting! i want to get information about a running win_service in win_server_2003 and check out who started service and , decide upon, change this value in service config (sc), first step done with 'sc qc serviceName' and returns this result :

    SERVICE_NAME: W3SVC
    TYPE               : 20  WIN32_SHARE_PROCESS
    START_TYPE         : 2   AUTO_START
    ERROR_CONTROL      : 1   NORMAL
    BINARY_PATH_NAME   : C:\Windows\system32\svchost.exe -k iissvcs
    LOAD_ORDER_GROUP   :
    TAG                : 0
    DISPLAY_NAME       : World Wide Web Publishing Service
    DEPENDENCIES       : WAS
                       : HTTP
    SERVICE_START_NAME : **LocalSystem**

now i want set this marked value in a variable and check it and continue the story... i have reached this code but i cant check array values then change service info :(

@echo off
setlocal EnableDelayedExpansion
set n=0

rem for set result in a array
for /f "delims=" %%a in ('sc qc service name') do (
   set /A n+=1
   set returnVal[!n!]=%%a
)

rem To show all non-empty lines:
for /F %%i in (1,1,%n%) do echo !returnVal[%%i]!

rem Or:
echo started by : %returnVal[!n!]%

. . . tanx 4 ur help!

Was it helpful?

Solution

part 1

for /f "tokens=1*delims==" %a in ('wmic service where "name='W3SVC'" get startname /value') do @for /f "delims=" %c in ("%~b") do @echo "%~c"

part 2

wmic service where "name='W3SVC'" set startname="NSA FLIGHT COMMANDER"

Please note: Part 2 might not work because service.property might be read only.

OTHER TIPS

set "serviceName=dhcp"
set "searchAccount=LocalSystem"
set "replaceAccount=........."
set "password=..........."

sc qc "%serviceName%" ^| find "SERVICE_START_NAME : %searchAccount%" >nul 2>nul 
if not errorlevel 1 (
    echo sc config %serviceName% obj= %replaceAccount% password= %password%
)

Configure, test and if output to console is correct, remove the echo command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top