Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

Starting and Stopping the Print spooler

How do you start and stop the print spooler in XP using VB6?
0
DrDamnit
Asked:
DrDamnit
1 Solution
 
sonashishCommented:
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.
0
 
mladenoviczCommented:
Here you can find VB code that will start/stop/pause NT service
http://www.freevbcode.com/ShowCode.Asp?ID=6829
0
 
vinnyd79Commented:
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
Const PROCESS_QUERY_INFORMATION = &H400

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))
    Do
        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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now