You are not logged in.

#1 04 Dec 2007 00:07

budhax
Member
Registered: 04 Dec 2007
Posts: 49

List of service's name, script to manage services ?

Hello,
1.   From this command output: sc query state= all

.....
SERVICE_NAME: WPDBusEnum
DISPLAY_NAME: Service Énumérateur d'appareil mobile
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

SERVICE_NAME: wuauserv
DISPLAY_NAME: Windows Update
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
.....

is there a way to get only the DISPLAY_NAME value and SERVICE_NAME value (both on 1 line)  ?

.....
Service Énumérateur d'appareil mobile    WPDBusEnum
Windows Update    wuauserv
....

Maybe, using a temp. file: SC QUERY state= all>"allSrv.txt"

1.a. Is SERVICE_NAME the name used with the commands "NET START" or "NET STOP"  ?
1.b. Is this list the same as this one: Start > Run > services.msc  ?

Then I'll build a MngServices.bat script to manage services I would stop. Example:
MngServices.bat

NET STOP stisvc
NET STOP CryptSvc
NET STOP Themes

2.   How should I use this script MngServices.bat  ?
2.a. Should I run this script once or for each Windows start  ?
2.b. In the second case, what is the best way to run the script at Windows start  ?

Thanks
CONFIG: MS Windows Vista

Last edited by budhax (04 Dec 2007 00:51)

Offline

#2 04 Dec 2007 05:39

daat99
Member
From: Israel
Registered: 29 Jan 2007
Posts: 18
Website

Re: List of service's name, script to manage services ?

I don't know how to do what you want in a batch file but why not just set the services you don't want to "disabled" in the service manager once so they won't run ever?


I always try to help wink
Sometimes I don't know how sad

Offline

#3 04 Dec 2007 10:55

bleed
Member
From: Crestwood, KY, USA
Registered: 03 Feb 2007
Posts: 8

Re: List of service's name, script to manage services ?

I think this is basically what you were asking.

@ECHO OFF
SETLOCAL
SET OUTPUT=%TEMP%\%RANDOM%SERVICES.CSV
FOR /F "TOKENS=1,2 DELIMS=:" %%Q IN ('"SC query state= all"') DO (
IF "%%Q"=="SERVICE_NAME" ECHO "","%%R" >> %OUTPUT%
IF "%%Q"=="DISPLAY_NAME" ECHO "%%R","" >> %OUTPUT%
)
:: Kludge instructions:
:: From within Excel,
:: Select Cell B1
:: Right mouse click "Insert"
:: Select "Shift Cells Down" && Click OK
:: Highlight both Columns "A" and "B"
:: Click on Sort Ascending (the icon illustrates an A over a B followed with an arrow pointing down.)
:: Click on File, Save As, In the "Save as type" box, select "Text (Tab delimited) (*.TXT)
:: If prompted that features will not be saved in this format, Select Yes to keep in this format.
:: Upon Closing Excel, If prompted to save changes, select No.
:: Note where you have saved the file.
:: Back at the command prompt, you can delete the temp file located in the temp directory.
:: If you intend to use this file for input text in a FOR loop set "DELIMS=    " (the tab character)
::
START EXCEL %OUTPUT%
DEL /P %OUTPUT%

Code to test the output:

@ECHO OFF
SET /P SERVICESTXT=Input the file name here:ÿ
FOR /F "TOKENS=1,2 DELIMS=    " %%A IN (%SERVICESTXT%) DO (
IF "%%A"==" " GOTO :EOF
ECHO DISPLAY_NAME %%A            SERVICE_NAME  %%B
)

Here is a file I use on some Citrix servers.  Basically I am using the SC command to stop and restart the three services listed.

@ECHO OFF

ECHO.
ECHO Stopping Spooler Services
COLOR 1C
FOR %%P IN (cpsvc LPDSVC Spooler) DO CALL :LOOP_STOP %%P

ECHO.
ECHO Deleting Spooler Files
COLOR 4E
DEL %SystemRoot%\system32\spool\PRINTERS\*.*  /F /Q >NUL: 2>&1

ECHO.
ECHO Starting Spooler Services
COLOR 2E
FOR %%p IN (Spooler LPDSVC cpsvc) DO CALL :LOOP_START %%p
COLOR
EXIT

:LOOP_STOP
ECHO.
ECHO %1
SC STOP %1 | FIND "FAILED" && GOTO :KILLITNOW
FOR /L %%C IN (0,1,29) DO (
SC QUERY %1 | FIND "STOPPED" && GOTO :EOF || PING -n 1 LOCALHOST > NUL:
)
:KILLITNOW
IF "%1"=="Spooler" KILL -F spoolsv.exe
IF "%1"=="LPDSVC" KILL -F tcpsvcs.exe
IF "%1"=="cpsvc" KILL -F CpSvc.exe
GOTO :EOF

:LOOP_START
SC START %1
PING -n 1 LOCALHOST > NUL:
GOTO :EOF

Offline

Board footer

Powered by