Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Torris
- Posts: 4
- Joined: 12 Jul 2012 00:58
#1
Post
by Torris » 12 Jul 2012 01:25
Hi.
im kind of new to scripting...
Im trying to make a .bat script that run with my admin credentials so it access the server, and then restarting the printerspooler.
Is this possible?
My printer server name: s0003119
And the spooler restart service i think i got right....

Net stop "print spooler"
net start "print spooler"
Thanks to any answer!
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#2
Post
by abc0502 » 12 Jul 2012 02:16
Here is the code:
@Echo off
Cls
Echo The Print Spooler service is stopping.
Net Stop spooler >nul
ping localhost -n 3 >nul
Echo The Print Spooler service is starting.
Net Start spooler >nul
Echo Service Restarted Sucessfully
ping localhost -n 3 >nul
Exit
The Main Commands are in red and the green command for waiting for about 3 secondes before running the next command
and the blue commands is for showing text in the command window, you can delete the blue and green if you want the command to be run quicly and without interface to the user, and leave the black command as it.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#3
Post
by foxidrive » 12 Jul 2012 02:41
I think he/she wants to do it on a remote machine.
You'd probably do it with PSEXEC but there would need to be error checking too, to ensure the service stopped before restarting it.
-
Torris
- Posts: 4
- Joined: 12 Jul 2012 00:58
#4
Post
by Torris » 12 Jul 2012 02:46
abc0502 wrote:Here is the code:
@Echo off
Cls
Echo The Print Spooler service is stopping.
Net Stop spooler >nul
ping localhost -n 3 >nul
Echo The Print Spooler service is starting.
Net Start spooler >nul
Echo Service Restarted Sucessfully
ping localhost -n 3 >nul
Exit
The Main Commands are in red and the green command for waiting for about 3 secondes before running the next command
and the blue commands is for showing text in the command window, you can delete the blue and green if you want the command to be run quicly and without interface to the user, and leave the black command as it.
Is it possible to send this command to the ip address of the printer? Where do i put the ip in the script?
-
Torris
- Posts: 4
- Joined: 12 Jul 2012 00:58
#5
Post
by Torris » 12 Jul 2012 02:53
foxidrive wrote:I think he/she wants to do it on a remote machine.
You'd probably do it with PSEXEC but there would need to be error checking too, to ensure the service stopped before restarting it.
Hi,
You are right. I am sitting on my personal pc. I have a printer server that i want to send this command to.
My printer ip example: 10.228.16.12
and thank you everyone for quick answers so far!:)
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#6
Post
by abc0502 » 12 Jul 2012 03:00
What is a printer server exactly, what system does it run?
-
Torris
- Posts: 4
- Joined: 12 Jul 2012 00:58
#7
Post
by Torris » 12 Jul 2012 03:05
abc0502 wrote:What is a printer server exactly, what system does it run?
We run windows server 2008, and have all the printer drivers installed on that server. if a printer stops we need to restart the printerspooler on the server.
So what i was thinking was is there a way running a script from my local computer to the server that restarts the printer spooler?
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#8
Post
by abc0502 » 12 Jul 2012 03:10
You can use the SC command to stop and start the service and using your example IP
Try this code:
SC \\10.228.16.12 stop spooler
SC \\10.228.16.12 start spooler
I couldn't test it because i don't have a server but try this commands from the command line if worked we can put them in a batch file then
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#9
Post
by abc0502 » 12 Jul 2012 03:33
You can follow
Foxidrive suggestion and download the PSTools from here :
http://technet.microsoft.com/en-us/sysinternals/bb896649.aspxand extract this command tool :
PsService.exe and double click on it and accept the license
then make this batch:
@Echo off
Cls
set "PsService=C:\PsService.exe"
%PsService% \\10.228.16.12 -u USERNAME -p PASSWORD restart spooler
Replace the red line with the directory of the tool "where you extracted it", and replace USERNAME and PASSWORD with your user and pass or remove the options in blue if not needed then run the batch