I need to check if a Windows service is installed from a batch file. I can dip into something other than batch if I need to, but I would prefer not to. Is there any way to do this?
views:
41answers:
4
+2
A:
you can run "net stop [servicename]" if it fails with "the service name is invalid" the service isn't installed
Climber104
2010-10-07 15:14:33
+1
A:
I'd say to make use of PowerShell. As this is exactly the type of issue it succeeds in.
Aaron
2010-10-07 15:15:36
-1 not a particularly helpful answer. Code examples would help him more than just a link to a technology.
John
2010-10-07 15:17:36
@John There are code examples. Did you go to the link? To many people rely on everything being embedded in SO...doesn't make since to regurgitate information from elsewhere.
Aaron
2010-10-07 15:21:12
I do prefer Powershell to batch, but I would rather not add that dependency to our build system. Thanks for your answer, though!
kerkeslager
2010-10-07 15:28:34
@john - that downvote is very unfair. That page does contain plenty of examples (see Introducing If.. Else Logic to WMI Services, there's a whole script that shows how to do this in PS). Not everything needs to be duplicated on SO.
Kev
2010-10-07 15:52:35
+2
A:
Try this:
@echo off
SC QUERY ftpsvc > NUL
IF ERRORLEVEL 1060 GOTO MISSING
ECHO EXISTS
GOTO END
:MISSING
ECHO SERVICE MISSING
:END
Note that the SC QUERY
command queries by the short service name not the display name. You can find this name by looking at the General tab of a service's properties in Service Manager.
Kev
2010-10-07 15:31:10
A:
James - built2order
2010-10-14 10:07:24