Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Query Service Status


  • Please log in to reply
16 replies to this topic
Homer
  • Members
  • 69 posts
  • Last active: May 13 2015 03:27 AM
  • Joined: 12 Jan 2006
How would one go about checking the Status of a Service?

I'm fine with using "Net Start / Stop" to manipulate the Service but I want to show the user the current Status and let them "Start" a Service that is not running and "Stop" a running Service.

Homer
  • Members
  • 69 posts
  • Last active: May 13 2015 03:27 AM
  • Joined: 12 Jan 2006
I've made a little progress with this but have hit another wall. There are some Services that are not TRUE Services. I found a crude solution and that is to leverage the output of the SC Command Line Utility for querying some Services but others fail. I can use SC Query "Service Name" and pipe the results out to a Text file and then read the Text file looking for the Service State. I then update my Gui to reflect the Status of the Service. This works fine. There are some Services though that the SC command will fail on. I get an error message like this:

[SC] EnumQueryServicesStatus:OpenService FAILED 1060:
The specified service does not exist as an installed service.

The part that puzzles me is that the Service in question does show up in the Services Console and I can Start and Stop it like all the other Services.

Anyone have any bright ideas?

Homer

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

EnumQueryServicesStatus:OpenService FAILED 1060:
The specified service does not exist as an installed service.


Which service did you attempt to query and what were the parameters to the program?

For example:

sc query lanmanworkstation

Homer
  • Members
  • 69 posts
  • Last active: May 13 2015 03:27 AM
  • Joined: 12 Jan 2006
From time to time I find code snippets of examples of how to Query a Status within VB. Is there anyway to leverage native OS objects from AHK? Can this be done in AHK?

Private Sub Command1_Click()
Dim manager As New dwServiceManager ' Control Manager object
Dim service As dwServiceObject ' represents a single service
Dim status As dwServiceStatus ' holds status information
Dim retval As Long' The first parameter is the machine name of the computer 
' which contains the services you want to manage.
retval = manager.InitializeSCManager("\\testmachine", "", _
SC_MANAGER_CONNECT)
Set service = manager.OpenService("SCardSvr", "Smart Card", _
SERVICE_START Or SERVICE_STOP Or SERVICE_QUERY_STATUS)' First we need to make sure the service is stopped before
' starting it.
Set status = service.QueryServiceStatus()
If (status.CurrentState <> SERVICE_STOPPED) then
  Exit Sub
End If' This starts a service.
service.StartService' This demonstrates how to wait until the service has
' actually started.
Do
  Set status = svc.QueryServiceStatus()
  Debug.Print status.CurrentState
Loop While (status.CurrentState <> SERVICE_RUNNING)
End Sub


Homer
  • Members
  • 69 posts
  • Last active: May 13 2015 03:27 AM
  • Joined: 12 Jan 2006
When I query a Service within SC and it works, it looks like this:
C:\>sc query alerter

SERVICE_NAME: alerter
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

When I run a query that doesn't work, it looks like this:
C:\>sc query "print spooler"
[SC] EnumQueryServicesStatus:OpenService FAILED 1060:

The specified service does not exist as an installed service.

Any comments...
Homer

Micha
  • Members
  • 539 posts
  • Last active: Dec 31 2011 01:43 PM
  • Joined: 15 Nov 2005
There is a difference between Displayname and Servername (exe). Sometimes you have to use the exe-name, sometimes the Displayname

The servicename is "SCardScr", the Displayname "Smartcard"

I have tried this:
net start SCardScr
Der Name für den Dienst ist ungültig.
Sie erhalten weitere Hilfe, wenn Sie NET HELPMSG 2185 eingeben.

sc sdshow SCardSvr
D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCLCSWRPWPDTLOCRRC;;;LS)(A;;CCDCLCSWRPWPDTLOCR
SDRCWDWO;;;BA)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;SO)(A;;CCLCSWRPLOCRRC;;;S-1-2-0)

sc GetDisplayName SCardSvr
[SC] GetServiceDisplayName SUCCESS  Name = Smartcard

net start Smartcard
Der angeforderte Dienst wurde bereits gestartet.

Have you tried both names?

Ciao
Micha

twhyman
  • Members
  • 348 posts
  • Last active: Sep 17 2014 01:55 AM
  • Joined: 07 Dec 2005
when using "net start/stop" you must use service_name and not display_name

i have been working on a script that chack what services are running and enables you to save a list to choose what services to close

iam producing a list of service to text file and then analyze the state of the
services

maybe we can help each other :) on the scripts

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005
Micha is right.

display name = "Print Spooler"
service name = Spooler

sc query spooler

You can determine the service name that corresponds to the display name with

sc query (list of all services)

or

sc getkeyname "print spooler"

or properties page of the service via the "Computer Management" console.

JSLover
  • Members
  • 920 posts
  • Last active: Nov 02 2012 09:54 PM
  • Joined: 20 Dec 2004
This is completely unrelated to solving his question, but does anyone know why ClipSrv, NetDDE & NetDDEDSDM run when I run clipbrd? I tried disabling some/all of them but when I did clipbrd either took a long time to or didn't open...I know these services provide features for sharing the clipboard, but I don't need to, I just want the clipboard to open & close fast, without starting & stopping the services everytime (ClipSrv is fine, but the NetDDE brings that window up everytime & takes time to start).
Useful forum links: New content since: Last visitPast weekPast 2 weeks (links will show YOUR posts, not mine)

OMFG, the AutoHotkey forum is IP.board now (yuck!)...I may not be able to continue coming here (& I love AutoHotkey)...I liked phpBB, but not this...ugh...

Note...
I may not reply to any topics (specifically ones I was previously involved in), mostly cuz I can't find the ones I replied to, to continue helping, but also just cuz I can't stand the new forum...phpBB was soo perfect. This is 100% the opposite of "perfect".

I also semi-plan to start my own, phpBB-based AutoHotkey forum (or take over the old one, if he'll let me)
PM me if you're interested in a new phpBB-based forum (I need to know if anyone would use it)
How (or why) did they create the Neil Armstrong memorial site (neilarmstronginfo.com) BEFORE he died?

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

ClipSrv, NetDDE & NetDDEDSDM


I am using XP SP2 and have disabled all three services without side-effects.

JSLover
  • Members
  • 920 posts
  • Last active: Nov 02 2012 09:54 PM
  • Joined: 20 Dec 2004

I am using XP SP2 and have disabled all three services without side-effects.

...meaning you can run & close clipbrd in less than a second (as fast as notepad)? XP (Home or Pro) SP2? I have XP Home SP1 (I don't wanna go thru the hassle of SP2 & all the "programs that may behave differently (MSKB)").
Useful forum links: New content since: Last visitPast weekPast 2 weeks (links will show YOUR posts, not mine)

OMFG, the AutoHotkey forum is IP.board now (yuck!)...I may not be able to continue coming here (& I love AutoHotkey)...I liked phpBB, but not this...ugh...

Note...
I may not reply to any topics (specifically ones I was previously involved in), mostly cuz I can't find the ones I replied to, to continue helping, but also just cuz I can't stand the new forum...phpBB was soo perfect. This is 100% the opposite of "perfect".

I also semi-plan to start my own, phpBB-based AutoHotkey forum (or take over the old one, if he'll let me)
PM me if you're interested in a new phpBB-based forum (I need to know if anyone would use it)
How (or why) did they create the Neil Armstrong memorial site (neilarmstronginfo.com) BEFORE he died?

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

...meaning you can run & close clipbrd in less than a second (as fast as notepad)?


I am assuming you're referring to ClipBook Viewer. Then yes, Notepad and ClipBook Viewer have similar start times.

XP (Home or Pro) SP2


Professional.

JSLover
  • Members
  • 920 posts
  • Last active: Nov 02 2012 09:54 PM
  • Joined: 20 Dec 2004

I am assuming you're referring to ClipBook Viewer.

...clipbrd.exe is the filename, I always start a cmd window & type clipbrd to run it.
Useful forum links: New content since: Last visitPast weekPast 2 weeks (links will show YOUR posts, not mine)

OMFG, the AutoHotkey forum is IP.board now (yuck!)...I may not be able to continue coming here (& I love AutoHotkey)...I liked phpBB, but not this...ugh...

Note...
I may not reply to any topics (specifically ones I was previously involved in), mostly cuz I can't find the ones I replied to, to continue helping, but also just cuz I can't stand the new forum...phpBB was soo perfect. This is 100% the opposite of "perfect".

I also semi-plan to start my own, phpBB-based AutoHotkey forum (or take over the old one, if he'll let me)
PM me if you're interested in a new phpBB-based forum (I need to know if anyone would use it)
How (or why) did they create the Neil Armstrong memorial site (neilarmstronginfo.com) BEFORE he died?

Homer
  • Members
  • 69 posts
  • Last active: May 13 2015 03:27 AM
  • Joined: 12 Jan 2006
ISSUE SOLVED -

This may not be the most elegant solution but it's going to work for my needs. After looking at the "SC" Command Line utility a little further I found a "Query State=" option that will give you a list of all the SERVICE & DISPLAY NAMES. The feed back from the list was correct, the Display name is not always a match for the SERVICE name and it's the SERVICE name that counts. (This is strange because I can use the Net Start Command with the Services I was interested in but they would not Query correctly with the SC utility.)

My solution is to send a SC command through RunWait, pipe the results out to a TXT file, read the file, then update my Gui.

Sample -
ServiceChk = sc query "Server Name" >"C:\Temp\ServiceCheck.txt"
runwait, %COMSPEC% /C %ServiceChk%, ,Hide  

FileRead, FileContent, C:\Temp\ServiceCheck.txt
Loop, Parse, FileContent, `n,`r
{
FileLine = %A_LoopField%
Lookfor = STATE
    IfInString, FileLine, %Lookfor%
        {
        StringGetPos, pointer, FileLine, :
        StringRight, ServerStatus, FileLine, StrLen(FileLine) - pointer - 5
        GuiControl, , Server, %ServerStatus% 
        }        
}
Return

When I want to Start or Stop the Service in question I run this -
command = NET START "Server Name"
runwait, %COMSPEC% /C %command%, , Hide

I'm having issues with my Splash Text not re-appearing when my Gui gets focus again but otherwise, this is working for me.

Thanks for the help,
Homer

Sentayehu Seifu
  • Guests
  • Last active:
  • Joined: --
I had this problem before,the problem can be solved by simply typing
Type from the command prompt:
#net start

and after Go back to services.msc and manually start the VMWARE Virtualcenter Server.

It was really annoying any ways it works for me.

Sentayehu Seifu