Reputation: 155
On w7 I want to receive the status of a service using psservice, since I want to do this on a remote computer later.
I try to get the batch script working on local machine first.
I have two issues: First issue is that "D:/PsService.exe query Server" will query ALL serviced containing the name "Server". I only want to query one specific service (in this example named "Server".
The other, bigger issue, is that my batch script are not working at all. It just "dies" (the CMD window immediately closes without execute the pause command, which make it extremely hard to debug).
I want to store the status of the service in a variable, which I gonna use later to compare example (IF %Status% EQ "RUNNING").
My code so far:
FOR /F token=3 %%i IN ('D:/PsService.exe query Server 2> NUL | find /I "STATE"') DO ( SET Status=%%i )
echo %Status%
pause
Why does the CMD just die and what am I doing wrong?
Upvotes: 0
Views: 5087
Reputation: 484
Following will work for you
@ECho off
for /F "tokens=3 delims=: " %%H in ('D:/PsService.exe query "SERVICE" ^| findstr " STATE"') do echo %%H
Upvotes: 2
Reputation: 11
echo off
set /P srvname="Enter the servername :"
echo %srvname%
set /P srvice="Enter the Service name :"
echo %srvice%
psservice.exe \\%srvname% query %srvice% >a.txt
a.txt
pause
Upvotes: 1