Status of an operating system service
Hey Guys.
Is possible i know in COS the state of the one service the operation system?
One example:
What's state of service WinDefend for example, in operating system Windows.
I would like to know the status of the service.
Comments
Figure out how you'd do it at a command prompt and then issue that command with $ZF(-1)
But, "$ZF(-1)" is not return result of execution command.
You see in documentation:
"$ZF(-1) does not return operating system command results"
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KE…
If the command you're using doesn't support redirection to a file use a command pipe e.g. SET $ZT="CommandErr" OPEN Command:"QR" FOR { USE Command READ Text USE $P ; do something with the text } CommandErr ; SET ZE=$ZE SET $ZT="" USE $P CLOSE Command IF $P(ZE,">")="<ENDOFFILE" { ; successful completion } ELSE { ; something happened }
test.mac:
<FONT COLOR="#0000ff">#include </FONT><FONT COLOR="#000000">%systemIncludeResult:</FONT><FONT COLOR="#0000ff">#define </FONT><FONT COLOR="#000000">getServState(%serviceName) </FONT><FONT COLOR="#0000ff">##class(%Activate.GenericObject).GetObject(</FONT><FONT COLOR="#008000">"winmgmts:\.\root\cimv2"</FONT><FONT COLOR="#0000ff">).InvokeMethod1(</FONT><FONT COLOR="#008000">"Get"</FONT><FONT COLOR="#0000ff">,$$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Win32_Service.Name=%1"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$quote</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">%serviceName</FONT><FONT COLOR="#000000">))</FONT><FONT COLOR="#0000ff">).GetProperty(</FONT><FONT COLOR="#008000">"State"</FONT><FONT COLOR="#0000ff">)
f </FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"wudfsvc"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"WSearch" </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">": "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$getServState</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">),!</FONT>
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^test</FONT> wudfsvc: Stopped WSearch: Running