Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking Print Spooler status (running or not)

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.

like image 400
Jon Story Avatar asked Dec 08 '25 18:12

Jon Story


1 Answers

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
like image 118
bill Avatar answered Dec 11 '25 10:12

bill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!