Solved

Wildcard Services restart

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

Accepted Solution

by:
dan_blagut earned 250 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

948 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

21 Experts available now in Live!

Get 1:1 Help Now