Restart print spooler on network machine
osaddict
London, UK
Hey all,
I have used the following script :
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!)
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!)
0
Comments
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"
I tried both - the simple and fancy ones - both gave me errors:
For the first one - just the two lines:
and for the one with messages:
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
If not on a domain, just create an identical username/password to your machines logon on the server and make it a local admin
Ill give it a go a bit later on this afternoon
Thanks again Shorty.
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.