1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Windows XP Services

Discussion in 'T&T - Scripting' started by Joe Caverly, Sep 1, 2009.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    487
    Likes Received:
    4
    If you are lacking in computer memory and system resources, one way that you can increase your computer memory and system resources is by stopping unnecessary services.

    If you do a Google search for “unnecessary windows xp services” you will find many web pages with information in regards to this subject.

    To see a list of all services currently running on my XP system, I type the following at the 4NT8 prompt;

    Code:
    sc query > clip: %+ list clip:
    While I have turned off several unnecessary windows xp services, there is one that I use on occasion. Until I need to use it, though, it is still taking up computer memory and system resources.

    In order to print from Windows XP, it is necessary to have the Print Spooler Service started.

    To check the status of the Print Spooler from the 4NT8 prompt, I type the following;

    Code:
    sc query spooler
    On my XP system, this returns;

    Code:
    SERVICE_NAME: spooler
            TYPE               : 110  WIN32_OWN_PROCESS (interactive)
            STATE              : 4  RUNNING
                                    (STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
            WIN32_EXIT_CODE    : 0  (0x0)
            SERVICE_EXIT_CODE  : 0  (0x0)
            CHECKPOINT         : 0x0
            WAIT_HINT          : 0x0
    
    There are two ways that I know of to stop the Print Spooler from the command prompt.

    First, you can type;

    Code:
    sc stop spooler
    
    Which returns the following;

    Code:
    SERVICE_NAME: spooler
            TYPE               : 110  WIN32_OWN_PROCESS (interactive)
            STATE              : 3  STOP_PENDING
                                    (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
            WIN32_EXIT_CODE    : 0  (0x0)
            SERVICE_EXIT_CODE  : 0  (0x0)
            CHECKPOINT         : 0x0
            WAIT_HINT          : 0x0
    
    
    Note that the state indicates STOP_PENDING. So, in order to be sure that the Spooler service is indeed stopped, I have to type;

    Code:
    sc query spooler
    
    Which returns;

    Code:
    SERVICE_NAME: spooler
            TYPE               : 110  WIN32_OWN_PROCESS (interactive)
            STATE              : 1  STOPPED
                                    (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
            WIN32_EXIT_CODE    : 0  (0x0)
            SERVICE_EXIT_CODE  : 0  (0x0)
            CHECKPOINT         : 0x0
            WAIT_HINT          : 0x0
    
    
    Note that the state indicates STOPPED.

    Another method to stop the Print Spooler from the command prompt is by using the NET command. From the command prompt, type;

    Code:
    net stop spooler
    
    This command takes a little longer, as it waits until the service has been stopped. On my XP system, it returns;

    Code:
    The Print Spooler service is stopping.
    The Print Spooler service was stopped successfully.
    
    Note also that the errorlevel of the command returns 0, indicating success. You can query the errorlevel of the command by typing the following at the prompt;

    Code:
    echo %?
    
    If you run the command again, an errorlevel of 2 is returned, because you cannot stop a service that is already stopped. Ditto for trying to start a service that is already started.

    To start the Print Spooler using the NET command, type;

    Code:
    net start spooler
    
    The WMI (Windows Management Instrumentation) offers a way to determine if a service is started or not. Here’s how to query the status of the Spooler using WMI from 4NT8;

    Code:
    @setlocal
    @if %_echo eq 1 @echo off
    if defined status unset status
    set status=%@wmi[root\cimv2,"select Started from Win32_Service Where Name = 'Spooler'"]
    if %status eq True echo Print Spooler is started
    if %status eq False echo Print Spooler is stopped
    endlocal
    
    WMI also allows you to start and stop services. Visit http://msdn.microsoft.com/en-us/library/aa394418(VS.85).aspx for more information.

    As noted in the 4NT8 help file, download the "WMI Code Creator" from Microsoft. This is a GUI front-end for WMI, that creates code for C#, Visual Basic .NET, and Visual Basic Script, and was quite useful in learning about WMI.

    Joe
     
    #1

Share This Page