Starting and Stopping the Print spooler

Posted on 2004-11-01
Last Modified: 2012-05-05
How do you start and stop the print spooler in XP using VB6?
Question by:DrDamnit
    LVL 2

    Expert Comment

    Try following, you ohly need to add reference of "Windows Script Host Object Model".

    Dim oShell, nError
    Set oShell = CreateObject("Wscript.Shell")
    nError = oShell.Run("net start spooler", 1, True)
    If nError = 0 Then Wscript.Echo "Spooler service started."

    Let me know it works or not.
    LVL 8

    Accepted Solution

    Here you can find VB code that will start/stop/pause NT service
    LVL 28

    Expert Comment

    You could also shell the command interpretor and wait for it to complete:

    Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
    Const STILL_ACTIVE = &H103

    Private Function ShellWait(PathName, Optional WindowStyle As VbAppWinStyle = vbNormalFocus) As Double
    Dim hProcess As Long, RetVal As Long
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(PathName, WindowStyle))
            GetExitCodeProcess hProcess, RetVal
            DoEvents: Sleep 100
        Loop While RetVal = STILL_ACTIVE
    End Function

    Private Sub Command1_Click()
    ShellWait Environ("Comspec") & " /c net start spooler", vbHide
    MsgBox "Spooler has started"
    End Sub

    Private Sub Command2_Click()
    ShellWait Environ("Comspec") & " /c net stop spooler", vbHide
    MsgBox "Spooler has stopped"
    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    759 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

    13 Experts available now in Live!

    Get 1:1 Help Now