1

I am trying to create a script that checks if the service Print Spooler is running or not.

The commands to start and stop, and check the status are listed below.

sc start Spooler # Starts service sc stop Spooler # Stops service sc query Spooler # Returns status of Spooler 

I wanted to hide the output of these commands from the user.

I wanted to check if the service is running.

If yes, then echo to user "Print Spooler already running." and then pause before close.

If no, then echo "Service stopped" then start the service and echo "Service starter" and then pause before close.

Any help will be appreciated.

1 Answer 1

0

Why would you want to do something so roundabout. We don't test then do, we do then test if it worked. Testing often uses the same resources as doing, so you chewed up twice the battery life, slowed other programs down TWICE.

@echo off sc start spooler>%temp%\status.txt findstr /c:"1056"<%temp%\status.txt>nul&&(Echo Service Already Running&pause&Goto :EOF) findstr /c:"FAILED"<%temp%\status.txt>nul&&(Echo Service Can't Start&pause&Goto :EOF)||(Echo Service Started&pause&Goto :EOF) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.