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.
Query Service Status
Started by
Homer
, Jan 16 2006 10:04 PM
16 replies to this topic
#1
-
Posted 16 January 2006 - 10:04 PM
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
[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
#2
-
Posted 17 January 2006 - 02:38 AM
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
#3
-
Posted 17 January 2006 - 02:47 AM
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
#4
-
Posted 17 January 2006 - 10:39 PM
When I query a Service within SC and it works, it looks like this:
When I run a query that doesn't work, it looks like this:
Any comments...
Homer
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
#5
-
Posted 17 January 2006 - 10:43 PM
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:
Have you tried both names?
Ciao
Micha
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
#6
-
Posted 18 January 2006 - 11:12 AM
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
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
#7
-
Posted 18 January 2006 - 11:24 AM
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.
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.
#8
-
Posted 18 January 2006 - 07:12 PM
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).
#9
-
Posted 18 January 2006 - 07:19 PM
Useful forum links: New content since: Last visit ■ Past week ■ Past 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?
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?
ClipSrv, NetDDE & NetDDEDSDM
I am using XP SP2 and have disabled all three services without side-effects.
#10
-
Posted 18 January 2006 - 07:55 PM
...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)").I am using XP SP2 and have disabled all three services without side-effects.
#11
-
Posted 18 January 2006 - 08:19 PM
Useful forum links: New content since: Last visit ■ Past week ■ Past 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?
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?
...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.
#12
-
Posted 18 January 2006 - 08:42 PM
...clipbrd.exe is the filename, I always start a cmd window & type clipbrd to run it.I am assuming you're referring to ClipBook Viewer.
#13
-
Posted 18 January 2006 - 09:19 PM
Useful forum links: New content since: Last visit ■ Past week ■ Past 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?
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?
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 -
When I want to Start or Stop the Service in question I run this -
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
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
#14
-
Posted 19 January 2006 - 01:28 AM
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
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
#15
-
Posted 20 August 2009 - 04:23 PM