2

I'm trying to use a SC command to act as a verification that a program installed, but I would like the query to return silently. Is there any way to use this without it returning the service's status?

sc query MSSQL$Company
if "%ERRORLEVEL%"=="0" (
GOTO Good
) else (
GOTO Bad
)
Richard-Degenne
  • 2,892
  • 2
  • 26
  • 43
ThexTallxDude
  • 137
  • 1
  • 1
  • 11
  • 3
    `sc query MSSQL$Company > NUL` – Aacini Aug 13 '16 at 16:54
  • Okay, sorry for such a simple question, then. What is the difference between /s and >null? – ThexTallxDude Aug 13 '16 at 17:42
  • 1
    `>null` redirects messages to a __file__ with name `null` created in current directory. The name of the device is `NUL` (just one L and not two) and therefore `>nul` must be used to really suppress messages. The command `sc` with sc command `query` does not support a parameter `/s` (silent) as some other Windows command line commands support. You should read the [documentation of sc](https://technet.microsoft.com/en-us/library/cc754599.aspx) like you should do for any Windows console command you want to use. – Mofi Aug 15 '16 at 13:54

1 Answers1

0

Like Aacini mentioned in the comments, you should use >NUL. This will pipe the output of the command (any command by the way) to nothing and therefore silence it. An example code snippet would be:

sc query MSSQL$Company >nul
if "%ERRORLEVEL%"=="0" (
GOTO Good
) else (
GOTO Bad
)
Excallypurr
  • 319
  • 1
  • 16