Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Wildcard Services restart

Posted on 2011-03-24
5
Medium Priority
?
2,140 Views
Last Modified: 2012-05-11
We have a server which runs multiple TOMCAT services.

The services are registered with a naming comvention --> SERVICE<PRACTICEName>

Currently, we have setup a .BAT file which lists all services to start / stop them...
eg.
net start SERVICEABC
net start SERVICEPLANT

net stop SERVICEABC
net stop SERVICEPLANT


We add new services all the time and the list grows and is difficult to maintain the batch file.

Is it possible to use a WILDCARD like 'net start SERVICE*' or something?
0
Comment
Question by:nainil
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:dan_blagut
ID: 35213265
Hello

if your services have one dependency in commun, normally when you restart that dependency service, all will be restarted. If not I will bet on a vbscript that pick the service name from a text file then restart it.

Dan
0
 

Author Comment

by:nainil
ID: 35213744
currently we mailtain a batch file whicl already lists all services. but we would like to move away from the same.

it is difficult to maintain the batch file with new services whick are added regularly.
0
 
LVL 22

Accepted Solution

by:
dan_blagut earned 1000 total points
ID: 35213796
Then you can use something like that :

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from win32_Service")
For each objService in colServices
    If left(objService.Name,7) = "Service_" Then
       objService.StopService()
       objService.StartService()
     End If
Next

In example the service name must begin with "Service_" (case sensitive).

Dan
0
 

Author Comment

by:nainil
ID: 35223651
Quick Question Dan_blaqut...

Is this something which I can use in a .bat file?

Or something else? how can one execute the same?
0
 

Author Comment

by:nainil
ID: 35224188
I figured it out :). used cscript "services.vbs" (which has the code).

Thank you dan_blagut for your time and efforts.

-Nainil C
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question