I am creating a batch file to start several services, instead of enumerating each "net start" with the exact service name, how can i create the script to run "net start" on any service that begins with "EED"
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
If you're open to using PowerShell instead of a batch file, this one liner will fix you up.
Get-Service EED* | Start-Service
A FOR-IN-DO loop is one way you could do this.
FOR %%x in ("Service 1" "Service 2" "Service ...") DO net start %%x
The syntax may vary, depending on the service name and optional parameters. Of course, this doesn't meet your requirement to enumerate the list based on service names that start with "EED." You will have to list each service specifically, or use more complex code to get that done. Type
FOR /? at a command prompt for more information on the extensive options that this command provides.
Here is a batch file to do exactly that:
@Echo Off for /f "tokens=1,2" %%i in ('sc query') do if "%%i"=="SERVICE_NAME:" call :Process %%j Goto :EOF :Process set @Name=%1 if "%@Name:~0,3%"=="EED" (SC start %1 Echo %1 Started) :EOF
If you want to change the "prefix search" change the line that says:
if "%@Name:~0,3%"=="EED" (SC start %1
The prefix to search for is the "EED" and you have to make sure that you change the length number, which is the "~0,3" part... if you want all services that start with "Exchange" then change that number to "~0,8"