VBScript: Stopping print spooler fails if another service is monitoring/controling it

Experts,

I have some functions written in VBScript that successfully stop/start the print spooler service.  This works great, unless there is some other utility that monitors/controls the spooler service.  Currently, my enemy is the Dell utilities that are installed if a printer was configured via the CD that came with the unit - but this could be ANY other utility that manages printers, such as HP, Kyocera, etc.

I've pasted what I have for functions in the code block below.  My question, is - would anybody be able to point me in the right direction on where I could get information on resolving my problem?

The print spooler service has no problem restarting by itself.  If one of the above mentioned utilities has control of the print spooler service, the original script just hangs (since the spooler service can't stop).

I need to stop (and most likely even disable) any service that has control over the print spooler service as well - if there are any.
Function PrintSpoolerStop
            objLogFile.WriteLine "                Stopping the Print Spooler service."
            wshShell.Run "net stop " & PrinterSpoolerService,0,True
                Do
                    Err = objSpoolerService.StopService()
                    WScript.Sleep 100
                Loop Until Err = 5
            objLogFile.WriteLine "                    Printer Spooler has stopped."
          End Function

        Function PrintSpoolerStart
            objLogFile.WriteLine "                Starting the Print Spooler service."
            wshShell.Run "net start " & PrinterSpoolerService,0,True
                Do
                    Err = objSpoolerService.StartService()
                    WScript.Sleep 100
                Loop Until Err = 10
            objLogFile.WriteLine "                    Printer Spooler has started."
          End Function

        Function PrintSpoolerRestart
            PrintSpoolerStop
            PrintSpoolerStart
          End Function

Open in new window

LVL 5
usslindstromAsked:
Who is Participating?
 
RobSampsonCommented:
Hi, have a look at the code here, which determines a service's dependencies, and stops them before stopping the required service:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa393673(v=vs.85).aspx

Regards,

Rob.
0
 
usslindstromAuthor Commented:
I'm looking at the solution you posted.  Give me a minute to work through what it's showing me...
0
 
usslindstromAuthor Commented:
That was it!  - Thank you VERY much for the assistance.
0
 
RobSampsonCommented:
No problem. Thanks for the grade.

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.