I'd like to run a command that will give me the status of a specific windows service. Using sc query, I was able to get this information, see below.
C:\Windows\System32>sc query "IBM Cognos"
SERVICE_NAME: IBM Cognos
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1077 (0x435)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
The only bit of information that I really need to access is the "STATE". Can I filter the output so I am only seeing the STATE or "1 STOPPED"? I was hoping I could do something like:
sc query[STATE] "IBM Cognos"
My ultimate goal is to run a .bat file that will output the status of a service to a file. I can then read that file from another program and use that value to determine whether I should display a green icon indicating "started" or a red icon indicating "stopped" to the user in the UI.
Thanks in advance for your help,
Jeff
How about:
sc query "IBM Cognos" | find "STATE"
Should return something like:
STATE : 1 STOPPED
Related
we bought a Printronix RFID printer T4304 with these dates:
FirmwareP301189 V1.21A
Serial NumberT4K431948007
Our wish is
to produce RFID-Labels with an QR-Code which includes the EPC-number
of the label. The QR-Code shall look like this:
http://qr.mycompany.com/epc/E280689123456789012345
We were hoping to use it with the Software Nicelabel. But Nicelabel
is only able to produce a QR-Code with only the EPC-Number but not
with our http://qr.my..../epc/ in front.
I had the idea to save the printjob as file. So I was able to
manipulate the file and send that file as printjob to the Printronix
printer like this:
lpr -S 192.168.1.2 -P raw myprintjob.prn
I found the document PTX_PRM_PGL_P7_253642C.pdf
which describes how the printer language is working. But I cannot
fulfill my destination.
My myprintjob.prn looks like this:
!PTX_SETUP
ENGINE-IMAGE_SHFT_H;0
ENGINE-IMAGE_SHFT_V;0
ENGINE-WIDTH;04146.
PTX_END
~NORMAL
~PIOFF
~DELETE LOGO;*ALL
~PAPER;INTENSITY 8;MEDIA 1;FEED SHIFT 0;CUT 0;PAUSE 0;TYPE 0;LABELS 2;SPEED IPS 6;SLEW IPS 6
~CREATE;FRM;99
SCALE;DOT;300;300
RFRTAG;96;EPC
96;DF511;H
STOP
ISET;0
FONT;FACE 92250
ALPHA
AF511;24;INV;POINT;329;1033;10;10;
STOP
BARCODE
QRCODE;INV;XD9;T2;E0;I1;95;843;
"http://qr.mycompany.com/epc/","EPCCODE"
STOP
END
~EXECUTE;FRM
~REPEAT;1
~AF511;<DF511>
~NORMAL
The result is a QRcode which only includes the first part of the string:
"http://qr.mycompany.com/epc/"
but not the "EPCCODE". I am looking for a hint how to do this.
Maybe I could find out the EPC-code via REST or telnet or so and create a special printjob for every single label?
Thanks for your help,
Richard
Printronix T4000, talk with port 9100 to get info from the printer
Author
Richard Lippmann, Stadt Zirndorf, EDV
Documentinformation
name: talk-with-port9100-to-get-infos-from-printronix-rfid-printer.md
revision: 2021-12-02 - init
What I want to achieve
I want to know the RFID-code from the label which is under the print-head.
With this information I am able to build a printjob with Qrcode which includes
the RFID-EPC.
I was not able to find out how to create a print-job with a qr-code.
I do not want this information in qrcode: ABC1234...567
But I want this information in qrcode: http://qr.mydomain.com/rfid/epc/ABC1234...567
With that I am able to take a picture of the label and go to a web-application
which helps me further with the device the label is on.
Documenation, where to find information
The printer language is described in the document which is easy to google: PTX_PRM_PGL_P7_253642C.pdf
My environment
Printronix T4000 printer with RFID-unit to read the RFID from the current label.
How to get info back from my printer
Usually Port 9100 is used to send a printjob to the Printronix-printer. Send job,
don't receive data. But you can switch the printer to be verbose, to send you
back information over the 9100-connection.
Glossary
EPC = this is the unique number which is in every RFID-label, just like
a MAC-address in a network card
PGL = the printer language. We can send printjobs with it, but also get information
from the printer about Configuration etc.
Human connect to the printer via Linux commandline
ssh me#shell.mydomain.com
export MYPRINTER=192.168.100.3
nc -v $MYPRINTER 9100
Put verbose mode on
The printer usually only receives information, but does not talk back.
You have to switch on the back-communication.
~CONFIG
SNOOP;STATUS
END
Put verbose mode off
I you are programming this interface with a programming
language like python, perl, ... it's a good idea to switch
verbose mode off after you did your job.
~CONFIG
SNOOP;OFF
END
IDENTITY
To see information:
put verbose mode on
send ~IDENTITY command
put verbose mode off
~CONFIG
SNOOP;STATUS
END
~IDENTITY
The result is:
T43040,V1.21A,12,131072KB
STATUS
To see information:
put verbose mode on
send ~IDENTITY command
put verbose mode off
~CONFIG
SNOOP;STATUS
END
~STATUS
The result is:
BUSY;0
PAPER;0
RIBBON;0
PRINT HEAD;0
COUNT;000
GAP;0
HEAD HOT;0
CUT COUNT;000000000
PRINT DIST;000001529
PRCT COMPLETE;000
TOF SYNCED;1
SENSED DIST;00450
END
Read one RFID-EPC-code from current label
These are things mentioned in this command:
~CREATE - start creating a new "form" (or subroutine to execute later)
VERIFY - the name of the subroutine we are creating. Keep it simple,
less than 15 characters, no special signs (see docu PTX_PRM_PGL_P7_253642C
page 60 under "CREATE" and page 29 under "Form Name" for exact informations)
NOMOTION - don't move the label to the next one after executing this job
DF511 = This is a variable-name, there seem to be a lot of variables in the printer
which are called by their numbers: DF1, DF2, ... I don't know which one I am
allowed to use, DF511 seems to work
96 = the RFID-EPC on my labels are 96 Bits long
H = Hexnumbers, the code is 96 Bit long, but I would like to see it like this:
ABC1234...567
VERIFY - a command to send information to the commandline.
~EXECUTE;VERIFY;1 - execute the form 1 time
~CONFIG
SNOOP;STATUS
END
~CREATE;VERIFY;432;NOMOTION
RFRTAG;96;EPC
96;DF511;H
STOP
VERIFY;DF511;H;*STARTEPC=*;*=ENDEPC\n*
END
~EXECUTE;VERIFY;1
~NORMAL
The result is:
STARTEPC=E28068940000501EC931EC87=ENDEPC
Read two RFID-EPC-codes
Reads 2 Barcodes and gives back the EPC-codes. With this command the label get
sent (moved) through the printer.
These are things mentioned in this command:
~CREATE - start creating a new "form" (or subroutine to execute later)
VERIFY - the name of the subroutine we are creating. Keep it simple,
less than 15 characters, no special signs (see docu PTX_PRM_PGL_P7_253642C
page 60 under "CREATE" and page 29 under "Form Name" for exact informations)
NOMOTION - don't move the label to the next one after executing this job
DF511 = This is a variable-name, there seem to be a lot of variables in the printer
which are called by their numbers: DF1, DF2, ... I don't know which one I am
allowed to use, DF511 seems to work
96 = the RFID-EPC on my labels are 96 Bits long
H = Hexnumbers, the code is 96 Bit long, but I would like to see it like this:
ABC1234...567
VERIFY - a command to send information to the commandline.
~EXECUTE;VERIFY;1 - execute the form 1 time
~CONFIG
SNOOP;STATUS
END
~CREATE;VERIFY;432
RFRTAG;96;EPC
96;DF511;H
STOP
VERIFY;DF511;H;*STARTEPC=*;*=ENDEPC\n*
END
~EXECUTE;VERIFY;2
~NORMAL
The result is:
STARTEPC=E28068940000501EC931EC87=ENDEPC
STARTEPC=E28068940000401EC931EC86=ENDEPC
A Windows service of type WIN32_SHARE_PROCESS (0x20) runs as a thread in a process which it shares with other services. (Although, in recent Windows 10 builds, it may get its own process anyway.) A Windows service of type WIN32_OWN_PROCESS (0x10) runs in its own isolated process. But, some Windows services have type wIN32_OWN_PROCESS | WIN32_SHARE_PROCESS (0x30). What does that combination mean?
sc query calls that combination WIN32. For example, sc query AppInfo reports:
SERVICE_NAME: AppInfo
TYPE : 30 WIN32
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
The Windows API docs don't mention this possibility. They talk about what each flag means independently, but not in combination. They do reference 0x30 in the documentation of EnumServicesStatusA, but in the context of that function it is documented as returning services with either types set, it doesn't talk about what it means for a service to have both types set.
(The service type field can take several other values: driver services like SERVIC_KERNEL_DRIVER, the SERVICE_INTERACTIVE_PROCESS flag, user services, etc. I am not asking about any of those other values/flags in this question, only about the 0x30 combination.)
As you point out, changes to service host grouping in Windows 10 may result in services of type SERVICE_WIN32_SHARE_PROCESS running in their own, isolated process. Whenever that happens to a service, SC will show it as SERVICE_WIN32 -- the confusing union of SERVICE_WIN32_OWN_PROCESS and SERVICE_WIN32_SHARE_PROCESS.
We've confirmed this situation by playing with the registry.
On our Windows 10 VM (which has ample RAM to trigger the process isolation enhancements), SC says AppInfo is of type WIN32 (30):
Task Manager reported that AppInfo was running in its own process.
As per the documentation, we disabled process isolation for the AppInfo service by adding the SvcHostSplitDisable value:
And after a reboot, SC reported AppInfo of type WIN32_SHARE_PROCESS (20):
The Task Manager confirmed that the process was indeed shared.
So its all down to those changes to service process isolation in Windows 10 Creators Update (version 1703).
I am using nexus 5 to test. How can i choose image from gallery using appium in android. When i used following code :
driver.findElement(By.xpath("//android.widget.ImageView[#content-desc='Photo
taken on 13 May 2016 12.50']")).click();
I got such Exception:
Exception in thread "main"
org.openqa.selenium.NoSuchElementException: An element could not be
located on the page using the given search parameters. (WARNING:The
server did not provide any stacktrace information) Command duration
or timeout: 50.56 seconds
Try with this:
driver.findElement(By.xpath("//*[#class='android.widget.ImageView' and #content-desc='Photo taken on 13 May 2016 12.50']")).click();
Try to write it with this manner it will select only the first :
driver.findElement(By.xpath("//android.widget.ImageView[contains(#resource-id,'id of your image')]")).click();
With this code you can select any elements you want just put instead of i the element you want starting from 0 for the first one :
driver.findElements(By.xpath("//android.widget.ImageView[contains(#resource-id,'id of your image')]")).get(i).click();
The best way is to go by creating xpath!
find_element(xpath: "//android.widget.FrameLayout[1]").click
Change your class name accordingly if different.
I am now facing a problem. when i check the erl_crash.dump, i found some stuff as below:
=proc:<0.19275.17>
State: Scheduled
Spawned as: proc_lib:init_p/5
Spawned by: <0.18723.17>
Started: Wed May 8 13:30:40 2013
Message queue length: 1
Number of heap fragments: 0
Heap fragment data: 0
Link list: [<0.20051.17>, <0.9976.18>, ..., **{from,<6524.13.0>,#Ref<6524.0.1.37040>}, {from,<6474.13.0>,#Ref<6474.0.1.36682>}, {from,<6470.13.0>,#Ref<6470.0.1.34219>}**, ...]
there is something like {from, Pid, Ref} in the link list of the proc <0.19275.17>.
i have no idea what these weird formed processes identifier are. i guess maybe it is related to "process monitoring". am i right? and i still want to know how can i generate such a process identifier and how can i make use of them ?
Thank you in advance :)
This means that the process was monitored by other processes. From documentation:
If process monitoring is used, this field also tells in which
direction the monitoring is in effect, i.e., a link being "to" a
process tells you that the "current" process was monitoring the other
and a link "from" a process tells you that the other process was
monitoring the current one.
You can find more infromation here
I think {from,<6524.13.0>,#Ref<6524.0.1.37040>} is that you register a global name, so global name server is monitoring this process.
more info: http://www.erlang.org/doc/man/global.html
I need to know the status of a service at the end of my batch script which restarts services using "net stop thingie" and "net start thingie".
In my most favorite ideal world, I would like to e-mail the state to myself, to read on cold winter nights, to reassure myself with the warmth and comfort of a server that I know is running right.
Just for you to know, I'm using a Windows server 2003 platform, and a batch file seemed the best choice. I don't mind using something else, and would be very open to suggestions, but just for the sake of knowledge (as a zombie craves brains, I thought, why not inflate my own), is there a command that allows me to check on the status of a service, in command line?
Should I just redirect the output of the command to a file?
Where the hell are my pants? (Gosh, I really do hope the humor inserted in this will not insult anyone. It's Wednesday morning, and humor I do need too :P)
[Edit:] The solution I used is (no longer) available for download from --link redacted--
It is used as a task set to be executed during the night, and checking my e-mail in the morning, I see whether or not the service has correctly restarted.
Have you tried sc.exe?
C:\> for /f "tokens=2*" %a in ('sc query audiosrv ^| findstr STATE') do echo %b
4 RUNNING
C:\> for /f "tokens=2*" %a in ('sc query sharedaccess ^| findstr STATE') do echo %b
1 STOPPED
Note that inside a batch file you'd double each percent sign.
You can call net start "service name" on your service. If it's not started, it'll start it and return errorlevel=0, if it's already started it'll return errorlevel=2.
Using pstools - in particular psservice and "query" - for example:
psservice query "serviceName"
look also hier:
NET START | FIND "Service name" > nul
IF errorlevel 1 ECHO The service is not running
just copied from:
http://ss64.com/nt/sc.html
If PowerShell is available to you...
Get-Service -DisplayName *Network* | ForEach-Object{Write-Host $_.Status : $_.Name}
Will give you...
Stopped : napagent
Stopped : NetDDE
Stopped : NetDDEdsdm
Running : Netman
Running : Nla
Stopped : WMPNetworkSvc
Stopped : xmlprov
You can replace the ****Network**** with a specific service name if you just need to check one service.
Using Windows Script:
Set ComputerObj = GetObject("WinNT://MYCOMPUTER")
ComputerObj.Filter = Array("Service")
For Each Service in ComputerObj
WScript.Echo "Service display name = " & Service.DisplayName
WScript.Echo "Service account name = " & Service.ServiceAccountName
WScript.Echo "Service executable = " & Service.Path
WScript.Echo "Current status = " & Service.Status
Next
You can easily filter the above for the specific service you want.
Well i see "Nick Kavadias" telling this:
"according to this http://www.computerhope.com/nethlp.htm it should be NET START /LIST ..."
If you type in Windows XP this:
NET START /LIST
you will get an error, just type instead
NET START
The /LIST is only for Windows 2000... If you fully read such web you would see the /LIST is only on Windows 2000 section.
Hope this helps!!!
my intention was to create a script which switches services ON and OFF (in 1 script)
net start NameOfSercive 2>nul
if errorlevel 2 goto AlreadyRunning
if errorlevel 1 goto Error
...
Helped a lot!! TYVM z666
but when e.g. service is disabled(also errorlevel =2?)it goes to "AlreadyRuning"and never comes to
if errorlevel 1 goto Error ?!!
i wanted an output for that case ...
:AlreadyRunning
net stop NameOfSercive
if errorlevel 1 goto Error
:Error
Echo ERROR!!1!
Pause
my 2 Cents, hope this helps
Maybe this could be the best way to start a service and check the result
Of course from inside a Batch like File.BAT put something like this example but just replace "NameOfSercive" with the service name you want and replace the REM lines with your own code:
#ECHO OFF
REM Put whatever your Batch may do before trying to start the service
net start NameOfSercive 2>nul
if errorlevel 2 goto AlreadyRunning
if errorlevel 1 goto Error
REM Put Whatever you want in case Service was not running and start correctly
GOTO ContinueWithBatch
:AlreadyRunning
REM Put Whatever you want in case Service was already running
GOTO ContinueWithBatch
:Error
REM Put Whatever you want in case Service fail to start
GOTO ContinueWithBatch
:ContinueWithBatch
REM Put whatever else your Batch may do
Another thing is to check for its state without changing it, for that there is a much more simple way to do it, just run:
net start
As that, without parameters it will show a list with all services that are started...
So a simple grep or find after it on a pipe would fit...
Of course from inside a Batch like File.BAT put something like this example but just replace "NameOfSercive" with the service name you want and replace the REM lines with your own code:
#ECHO OFF
REM Put here any code to be run before check for Service
SET TemporalFile=TemporalFile.TXT
NET START | FIND /N "NameOfSercive" > %TemporalFile%
SET CountLines=0
FOR /F %%X IN (%TemporalFile%) DO SET /A CountLines=1+CountLines
IF 0==%CountLines% GOTO ServiceIsNotRunning
REM Put here any code to be run if Service Is Running
GOTO ContinueWithBatch
:ServiceIsNotRunning
REM Put here any code to be run if Service Is Not Running
GOTO ContinueWithBatch
:ContinueWithBatch
DEL -P %TemporalFile% 2>nul
SET TemporalFile=
REM Put here any code to be run after check for Service
Hope this can help!! It is what i normally use.
Well I'm not sure about whether you can email the results of that from a batch file. If I may make an alternate suggestion that would solve your problem vbscript. I am far from great with vbscript but you can use it to query the services running on the local machine. The script below will email you the status of all of the services running on the machine the script gets run on. You'll obviously want to replace the smtp server and the email address. If you're part of a domain and you run this script as a privileged user (they have to be an administrator on the remote machine) you can query remote machines as well by replacing localhost with the fqdn.
Dim objComputer, objMessage
Dim strEmail
' If there is an error getting the status of a service it will attempt to move on to the next one
On Error Resume Next
' Email Setup
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Service Status Report"
objMessage.From = "service_report#noreply.net"
objMessage.To = "youraddress#example.net"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.example.net"
'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Set objComputer = GetObject("WinNT://localhost")
objComputer.Filter = Array("Service")
For Each aService In objComputer
strEmail = strEmail &chr(10) & aService.Name & "=" & aService.Status
Next
objMessage.TextBody = strEmail
objMessage.Configuration.Fields.Update
objMessage.Send
Hope this helps you! Enjoy!
Edit: Ahh one more thing a service status of 4 means the service is running, a service status of 1 means it's not. I'm not sure what 2 or 3 means but I'm willing to bet they are stopping/starting.
according to this http://www.computerhope.com/nethlp.htm it should be NET START /LIST but i can't get it to work on by XP box. I'm sure there's some WMI that will give you the list.
Ros the code i post also is for knowing how many services are running...
Imagine you want to know how many services are like Oracle* then you put Oracle instead of NameOfSercive... and you get the number of services like Oracle* running on the variable %CountLines% and if you want to do something if there are only 4 you can do something like this:
IF 4==%CountLines% GOTO FourServicesAreRunning
That is much more powerfull... and your code does not let you to know if desired service is running ... if there is another srecive starting with same name... imagine:
-ServiceOne
-ServiceOnePersonal
If you search for ServiceOne, but it is only running ServiceOnePersonal your code will tell ServiceOne is running...
My code can be easly changed, since it reads all lines of the file and read line by line it can also do whatever you want to each service... see this:
#ECHO OFF
REM Put here any code to be run before check for Services
SET TemporalFile=TemporalFile.TXT
NET START > %TemporalFile%
SET CountLines=0
FOR /F "delims=" %%X IN (%TemporalFile%) DO SET /A CountLines=1+CountLines
SETLOCAL EnableDelayedExpansion
SET CountLine=0
FOR /F "delims=" %%X IN (%TemporalFile%) DO #(
SET /A CountLine=1+CountLine
REM Do whatever you want to each line here, remember first and last are special not service names
IF 1==!CountLine! (
REM Do whatever you want with special first line, not a service.
) ELSE IF %CountLines%==!CountLine! (
REM Do whatever you want with special last line, not a service.
) ELSE (
REM Do whatever you want with rest lines, for each service.
REM For example echo its position number and name:
echo !CountLine! - %%X
REM Or filter by exact name (do not forget to not remove the three spaces at begining):
IF " NameOfService"=="%%X" (
REM Do whatever you want with Service filtered.
)
)
REM Do whatever more you want to all lines here, remember two first are special as last one
)
DEL -P %TemporalFile% 2>nul
SET TemporalFile=
REM Put here any code to be run after check for Services
Of course it only list running services, i do not know any way net can list not running services...
Hope this helps!!!