Solved

Wildcard Services restart

Posted on 2011-03-24
5
1,985 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 21

Expert Comment

by:dan_blagut
Comment Utility
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
Comment Utility
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 21

Accepted Solution

by:
dan_blagut earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
Know what services you can and cannot, should and should not combine on your server.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now