Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ros the code i post also is for knowing how many services are running...</p> <p>Imagine you want to know how many services are like Oracle* then you put Oracle instead of NameOfSercive... and you get the number of services like Oracle* running on the variable %CountLines% and if you want to do something if there are only 4 you can do something like this:</p> <p>IF 4==%CountLines% GOTO FourServicesAreRunning</p> <p>That is much more powerfull... and your code does not let you to know if desired service is running ... if there is another srecive starting with same name... imagine: -ServiceOne -ServiceOnePersonal</p> <p>If you search for ServiceOne, but it is only running ServiceOnePersonal your code will tell ServiceOne is running...</p> <p>My code can be easly changed, since it reads all lines of the file and read line by line it can also do whatever you want to each service... see this:</p> <pre><code>@ECHO OFF REM Put here any code to be run before check for Services SET TemporalFile=TemporalFile.TXT NET START &gt; %TemporalFile% SET CountLines=0 FOR /F "delims=" %%X IN (%TemporalFile%) DO SET /A CountLines=1+CountLines SETLOCAL EnableDelayedExpansion SET CountLine=0 FOR /F "delims=" %%X IN (%TemporalFile%) DO @( SET /A CountLine=1+CountLine REM Do whatever you want to each line here, remember first and last are special not service names IF 1==!CountLine! ( REM Do whatever you want with special first line, not a service. ) ELSE IF %CountLines%==!CountLine! ( REM Do whatever you want with special last line, not a service. ) ELSE ( REM Do whatever you want with rest lines, for each service. REM For example echo its position number and name: echo !CountLine! - %%X REM Or filter by exact name (do not forget to not remove the three spaces at begining): IF " NameOfService"=="%%X" ( REM Do whatever you want with Service filtered. ) ) REM Do whatever more you want to all lines here, remember two first are special as last one ) DEL -P %TemporalFile% 2&gt;nul SET TemporalFile= REM Put here any code to be run after check for Services </code></pre> <p>Of course it only list running services, i do not know any way net can list not running services...</p> <p>Hope this helps!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload