Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to email print spooler service status 1

Status
Not open for further replies.

windowsfan

IS-IT--Management
Jan 26, 2007
237
US
I need help with a script which I can schedulet to run every 10 mins and check the status on the print spooler services and send out email to admins and start the print spooler if it was off. I am trying the belwo script I found online but it is now working.

strComputer = "."
strService = "Print Spooler"

Set objEmail = CreateObject("CDO.Message")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where DisplayName = '" & Service & "'")
For Each objItem in colItems
If objItem.status <>"OK" or objItem.state <>"Running" then
objEmail.From = "Email Address"
objEmail.To = "Email Address"
objEmail.Subject = "Print Spooler Service"
objEmail.Textbody = objItem.DisplayName & " on: " & strComputer _
'" State: " & objItem.State & VbCrLf
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = _
"smtp"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
Next
 
There is a type in above thread.
I am trying the script in the above thread which I found online but it is not working.

 
Use the following:

strComputer = "."
strService = "Print Spooler"
Set objEmail = CreateObject("CDO.Message")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service where DisplayName = '" & strService & "'")
For Each objItem in colItems
If objItem.status <>"OK" or objItem.state <>"Running" then
objEmail.From = "name.lastname@acme.xxx"
objEmail.To = "name2.lastname@acme.xxx"
objEmail.Subject = "Print Spooler Service"
objEmail.Textbody = objItem.DisplayName & " on: " & strComputer & " State: " & objItem.State & VbCrLf
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = "smtp.server@acme.xxx"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
Next
 
You can use the following to start the spooler:

sc \\server config "Print Spooler" start= auto – This will set startup type to auto
sc \\server start "Print Spooler"
 
How can I edit the code to start the spooler when it is off?
 
Well now that you've force me to think about it(just kidding), you can add the following after the objEmail.Send line:

objItem.StartService()
 
Hello TheKidd. I have a similar question/problem. I am trying to find a VB script that will start a service in a Windows environment. The server is a: Windows Server 2003 Service Edition Service Pack 2.

The server that continues to die and required a manual restart is: PureActiv Video Processor

I would like a script that will email me and my group every time it dies. Any chances you can assist me?


I don't know if you need this information but I'll give it to you:

"C:\Program Files\PureTech Systems\PureActivDAQServices\Pure.PureLink.VideoProcessor.VideoProcessorService.exe"

Thanks in advance,
-laststock007
 
You should be able to use the same script. Just change the strService = "Print Spooler" line to strService = "PureActiv Video Processor
 
One thing you need to be aware of is that the majority of spooler issues are the result of a spooler hang where the service state will remain running, this drastically reduces the usefulness of the script.

I've found the best solution is to simply schedule restarting the spooler service in the evening.

At one customer I also gave them an ASP web page that allowed users to restart the spooler if it was in fact hung.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top