Solved

Script to enable auto recovery?

Posted on 2007-12-05
6
387 Views
Last Modified: 2012-06-27
We have a few printers that are causing the print spooler service on computers around the company to stop.

Is there a way to script a logon file that can set the recovery options under the print spooler service to automatically restart if failed and set the option for delay to 3 minutes?

0
Comment
Question by:Icetoad
  • 4
  • 2
6 Comments
 
LVL 7

Expert Comment

by:avatar-e
ID: 20412689
This script keeps prints spooler alive, checking every 3 minutes
' ReStartService.vbs

' Sample script to Stop or Start a Service

' www.computerperformance.co.uk/

' Created by Guy Thomas December 2005 Version 2.4

' -------------------------------------------------------' 

Option Explicit

Dim objWMIService, objItem, objService

Dim colListOfServices, strComputer, strService, intSleep 

strComputer = "."

intSleep = 180000

'WScript.Echo " Click OK, then wait " & intSleep & " milliseconds" 
 

'On Error Resume Next

' NB strService is case sensitive.

strService = " 'Spooler' "

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" _

& strComputer & "\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery _

("Select * from Win32_Service Where Name ="_

& strService & " ")
 

While true

For Each objService in colListOfServices

objService.StartService()

WSCript.Sleep intSleep

Next 

wend

WScript.Echo "Your "& strService & " service has Started" 

WScript.Quit

' End of Example WMI script to Start / Stop services

Open in new window

0
 
LVL 7

Expert Comment

by:avatar-e
ID: 20412698
Save to a VBS file and double click it (or put in the startup folder in the faulty print server)
0
 
LVL 8

Author Comment

by:Icetoad
ID: 20412756
Thats a nifty script... question though.

I would be using this for computers in which users login.   If its apart of the login script, wouldnt it cause mutliple instances of this script to run?
0
Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

 
LVL 7

Expert Comment

by:avatar-e
ID: 20413413
You can put the script just in the admin account to start it once, on the startup folder in start menu / programs. (If you start as admin first).

0
 
LVL 7

Accepted Solution

by:
avatar-e earned 500 total points
ID: 20413529
Anyways I modified the code a bit, now only last instance will survive, so you can run many time as you like without the worry of having thousand instances running
' ReStartService.vbs

' Sample script to Stop or Start a Service

' www.computerperformance.co.uk/

' Created by Guy Thomas December 2005 Version 2.4

' -------------------------------------------------------' 

Option Explicit

Dim WshShell

set WshShell = CreateObject("wscript.Shell")

Dim objWMIService, objItem, objService

Dim colListOfServices, strComputer, strService, intSleep 

strComputer = "."

intSleep = 180000

'On Error Resume Next

strService = " 'Spooler' "

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" _

& strComputer & "\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery _

("Select * from Win32_Service Where Name ="_

& strService & " ")
 

Dim myProcId

randomize

myProcId = "SpoolerAlive_" & Int(Rnd()*99999) & "_" & Int(Rnd()*99999)

Dim lastProcessId

lastProcessId = myProcId

Dim myReg 

myReg = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Spooler_alive_last"

WshShell.RegWrite myReg, myProcId
 

While lastProcessId = myProcId

	lastProcessId = ""

	For Each objService in colListOfServices

		objService.StartService()

		WSCript.Sleep intSleep

	Next 

	lastProcessId =WshShell.RegRead(myReg)

wend

WScript.Quit

' End of Example WMI script to Start / Stop services

Open in new window

0
 
LVL 8

Author Closing Comment

by:Icetoad
ID: 31412873
Thanks.. not exactly what i wanted, but its actually a better solution :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pdf convertor 7 66
Bulk Reorder File Names 4 56
Dual boot for S.O 7 33
egit plugin on eclipse 8 37
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now