Jump to content

command line questions


Zxian

Recommended Posts

Hey everyone,

I'm trying to make some batch files that you can run to toggle the status of a service (in particular, the print spooler).

I'd like to make the batch file something like...

@echo off

IF "print service started" (

net stop spooler

) ELSE (

net start spooler

I'd like to keep my spooler service disabled unless I need to print something (usually only with Acrobat PDF) and I'd like a quick link to do this from the start menu or such.

Any help would be appreciated.

Thanks!

Link to comment
Share on other sites


best way would IMO be to check the status of it via registry.. do a read from reg

i think the cmd is:

set test REG READ key /v subkey /d value

if %test% = 2 goto good ELSE goto BAD

exit

:net stop spooler

2 = auto

3 = manual

4 = disabled

find the services reg key for spooler

Link to comment
Share on other sites

I think you're gonna have many tips for that.

There's mine...

@echo off

FOR /F "tokens=1,2,3,4" %%A IN ('SC.EXE QUERY SPOOLER ^| FIND /I "STATE"') DO SET STATE=%%D

IF /I "%STATE%"=="RUNNING" (NET STOP SPOOLER) ELSE (NET START SPOOLER)

Link to comment
Share on other sites

yours looks better jdoe :P much more professional :P

Your idea was not bad but reading the start value of a service don't give the live state of this service. The start value can be "2" (automatic) and the service can also be in a stopped state. ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...