I need to detect whether the Print Spooler service is running. I can find various resources for VB.NET (e.g., using ServiceProcess.ServiceController
to actually manipulate the service), but nothing for VB6.
Is there any way to check whether the Print Spooler is running in VB6? And ideally start it, but I can survive without that.
We use wmi in VBA/VB6/VBScript and command prompt.
This lists processes
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
For Each objItem in colItems
msgbox objitem.name & " PID=" & objItem.ProcessID & " SessionID=" & objitem.sessionid
' objitem.terminate
Next
This is typed an command prompt.
wmic process get
You'll see you can get VBS methods/properties by using wmic help
wmic /? wmic process /? wmic process get /?
So wmic service get caption,status
so
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Service")
For Each objItem in colItems
msgbox objitem.name & " " & objitem.status
Next