Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Wildcard Services restart

Posted on 2011-03-24
5
Medium Priority
?
2,115 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

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…
Learn about cloud computing and its benefits for small business owners.
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.

715 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