Restart print spooler on network machine

osaddictosaddict London, UK
edited April 2007 in Internet & Media
Hey all,


I have used the following script :
'This code will stop and start the print spooler service
'---SCRIPT CONFIGURATION---
strComputer = "."
'---END CONFIGURATION---
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='Spooler'")
For each objService in colServiceList
     errReturn = objService.StopService()
Next
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='Spooler'")
For each objService in colServiceList
     errReturn = objService.StartService()
Next
'WScript.Echo ("Script Complete")

This works exactally as I want it to, however, to run this script manually (as is sometimes required) I have to log in to the remote machine via terminal services - being a slowish machine it takes a while.

Could I edit this script so that I can run it from MY pc but restart the spooler on a different pc (within our network)

(I know very very little about scripting - I just got that script from the net!)

Comments

  • ShortyShorty Manchester, UK Icrontian
    edited April 2007
    That is way more technical than it needs to be. While very elegant, there is a much simpler nifty way of doing it :)

    Try this:

    Create a text document in notepad. Put the following two lines in it:

    sc \\MACHINENAME stop "Spooler"
    sc \\MACHINENAME start "Spooler"

    Change MACHINENAME to be the server you want to stop/start the service on.

    So it would look something like this:

    sc \\server1.mydomain.msft stop "Spooler"
    sc \\server1.mydomain.msft start "Spooler"

    Save as restartSpooler.bat

    Run it when you need to :)

    You can of course fancy that up to query status messages and print friendly messages.

    Eg...

    @ECHO OFF
    sc \\server1.mydomain.msft stop "Spooler"
    ECHO "Spooler stopped"
    sc \\server1.mydomain.msft start "Spooler"
    ECHO "Spooler started"
    sc \\server1.mydomain.msft query "Spooler"
  • osaddictosaddict London, UK
    edited April 2007
    Hey Shorty,

    I tried both - the simple and fancy ones - both gave me errors:

    For the first one - just the two lines:
    C:\>STARTSPOOLER.BAT
    
    C:\>sc \\BACKUPARCHIVE stop "Spooler"
    [SC] OpenSCManager FAILED 5:
    
    Access is denied.
    
    
    C:\>sc \\BACKUPARCHIVE start "Spooler"
    [SC] OpenSCManager FAILED 5:
    
    Access is denied.
    
    

    and for the one with messages:
    C:\>SPOOLER2.BAT
    [SC] OpenSCManager FAILED 1722:
    
    The RPC server is unavailable.
    
    "Spooler stopped"
    [SC] OpenSCManager FAILED 1722:
    
    The RPC server is unavailable.
    
    "Spooler started"
    [SC] OpenSCManager FAILED 1722:
    
    The RPC server is unavailable.
    

    With my very limited knowledge, the first one looks like it may require the password of the machine to be in the script?

    The second one - the rpc server thing is the bain of my life - i get that error quite a lot - intermittently - i checked that the rpc and rpc locator were started on my machine - both were.

    Thanks!
    Rob
  • ShortyShorty Manchester, UK Icrontian
    edited April 2007
    Is the machine in a domain? If so, add your user account as a local admin. That will clear up both errors :)

    If not on a domain, just create an identical username/password to your machines logon on the server and make it a local admin :)
  • osaddictosaddict London, UK
    edited April 2007
    It's not on a domain no, so the latter of the solutions would have to be the one.

    Ill give it a go a bit later on this afternoon :)

    Thanks again Shorty.
  • edited April 2007
    So does the following mean that I was successful in restarting the print spooler:

    sc \\servername start "spooler"
    SERVICE_NAME: spooler
    TYPE : 110 WIN32_OWN_PROCESS <INTERACTIVE>
    STATE : 2 START_PENDING <NOT_STOPPABLE,NOT_PUUSEABLE,IGNORES_SHUTDOWN>
    WIN32_EXIT_CODE : 0 <0x0>
    SERVICE_EXIT_CODE: 0 <0x0>
    CHECKPOINT : 0x1
    WAIT_HINT : 0x4e20
    PID : 7812
    FLAGS :

    I got a very similar message when I first ran stop "spooler" from the same client computer. I have attached screen shots of both the start and stop responses. Thanks very much for your help.
Sign In or Register to comment.