A Windows XP help forum. PCbanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » PCbanter forum » Microsoft Windows 7 » Windows 7 Forum
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Issuing 'SC Stop' for service - but waiting until stopped ?



 
 
Thread Tools Rate Thread Display Modes
  #1  
Old December 27th 15, 04:37 PM posted to alt.windows7.general
(PeteCresswell)
external usenet poster
 
Posts: 1,933
Default Issuing 'SC Stop' for service - but waiting until stopped ?

I want to delete a bunch of IP cam output files, but do not want the
..BAT file to hang for such a long time because the cam server
has some files IN USE.

So I want to stop the service, delete the files, and then
re-start the service.

I do not want the service to start automagically while the
delete are in progress.

viz:
================================================== =============
sc stop BlueIris
sc config BlueIris start= disabled

ERASE B:\Alerts\*.* /Q
ERASE B:\Clips \*.* /Q
ERASE B:\Clips_Stored\*.* /Q
ERASE B:\DB\*.* /F /Q

sc start BlueIris
sc config BlueIris start= auto

ECHO OFF
ECHO .
ECHO .
ECHO . ------------ Done! -------------
ECHO .
ECHO .
PAUSE
================================================== ================

It's almost working, but not quite.

According to "Services.msc", the BlueIris service is left in a
"Stopping" state and attempts to re-start it or go at it
via the SC command do not work.

viz:
================================================== ================
C:\BATsc stop BlueIris
[SC] ControlService FAILED 1061:

The service cannot accept control messages at this time.


C:\BATsc config BlueIris start= disabled
[SC] ChangeServiceConfig SUCCESS

C:\BATERASE B:\Alerts\*.* /Q

C:\BATERASE B:\Clips \*.* /Q

C:\BATERASE B:\Clips_Stored\*.* /Q

C:\BATERASE B:\DB\*.* /F /Q

C:\BATsc start BlueIris
[SC] StartService FAILED 1056:

An instance of the service is already running.


C:\BATsc config BlueIris start= auto
[SC] ChangeServiceConfig SUCCESS

C:\BATECHO OFF
..
..
.. ------------ Done! -------------
..
..
Press any key to continue . . .
================================================== ================

Am I going at this the wrong way ?
--
Pete Cresswell
Ads
  #2  
Old December 27th 15, 05:47 PM posted to alt.windows7.general
David E. Ross[_2_]
external usenet poster
 
Posts: 1,035
Default Issuing 'SC Stop' for service - but waiting until stopped ?

On 12/27/2015 8:37 AM, (PeteCresswell) wrote:
I want to delete a bunch of IP cam output files, but do not want the
.BAT file to hang for such a long time because the cam server
has some files IN USE.

So I want to stop the service, delete the files, and then
re-start the service.

I do not want the service to start automagically while the
delete are in progress.

viz:
================================================== =============
sc stop BlueIris
sc config BlueIris start= disabled

ERASE B:\Alerts\*.* /Q
ERASE B:\Clips \*.* /Q
ERASE B:\Clips_Stored\*.* /Q
ERASE B:\DB\*.* /F /Q

sc start BlueIris
sc config BlueIris start= auto

ECHO OFF
ECHO .
ECHO .
ECHO . ------------ Done! -------------
ECHO .
ECHO .
PAUSE
================================================== ================

It's almost working, but not quite.

According to "Services.msc", the BlueIris service is left in a
"Stopping" state and attempts to re-start it or go at it
via the SC command do not work.

viz:
================================================== ================
C:\BATsc stop BlueIris
[SC] ControlService FAILED 1061:

The service cannot accept control messages at this time.


C:\BATsc config BlueIris start= disabled
[SC] ChangeServiceConfig SUCCESS

C:\BATERASE B:\Alerts\*.* /Q

C:\BATERASE B:\Clips \*.* /Q

C:\BATERASE B:\Clips_Stored\*.* /Q

C:\BATERASE B:\DB\*.* /F /Q

C:\BATsc start BlueIris
[SC] StartService FAILED 1056:

An instance of the service is already running.


C:\BATsc config BlueIris start= auto
[SC] ChangeServiceConfig SUCCESS

C:\BATECHO OFF
.
.
. ------------ Done! -------------
.
.
Press any key to continue . . .
================================================== ================

Am I going at this the wrong way ?


Why not put a Pause after the Erase statements? Include some
human-oriented text in the Pause statement. Then when all erasing is
done, you hit the space bar on your keyboard to continue.

--
David E. Ross

Pharmaceutical companies claim their drug prices are
so high because they have to recover the costs of developing
those drugs. Two questions:

1. Why is the U.S. paying the entire cost of development while
prices for the same drugs in other nations are much lower?

2. Manufacturers of generic drugs did not have those
development costs. Why are they charging so much for generics?
  #3  
Old December 27th 15, 07:26 PM posted to alt.windows7.general
Andy Burns[_3_]
external usenet poster
 
Posts: 399
Default Issuing 'SC Stop' for service - but waiting until stopped ?

(PeteCresswell) wrote:

I want to stop the service, delete the files, and then
re-start the service.


Loop with a sleep and repeatedly match the status with

sc query wudfsvc | find /i "state"

break out when it's no longer running, or error out after too many loops?


  #5  
Old December 27th 15, 10:23 PM posted to alt.windows7.general
Andy Burns[_3_]
external usenet poster
 
Posts: 399
Default Issuing 'SC Stop' for service - but waiting until stopped ?

pjp wrote:

Isn't there a "/wait" option for cmd?


There's start.exe /wait ....

Run the "stop service" command
under a called new shell from within the batch file with the wait
parameter. When it returns the service should be stopped or else some
"errorlevel" code should result that you can test how to continue.


But you'll only be waiting until sc.exe has issued the stop command to
the Service Control Manager, not until it has taken effect, the service
could get stuck in "stopping" state ..

  #6  
Old December 27th 15, 10:37 PM posted to alt.windows7.general
Mayayana
external usenet poster
 
Posts: 6,438
Default Issuing 'SC Stop' for service - but waiting until stopped ?

I don't know whether you want to deal with WMI.
It's a bit tedius and the object model is funky. But
it's an option that provides a more "comfy" set of
functions than using command line. WMI is designed
for this kind of thing, while BAT files are more of
a hack approach.
A VBScript example follows. The methods return
values, so you don't have to wait and wonder when
the service has stopped. The function doesn't return
until there's a result:

Dim WMI, oServ, Ret, StartName

' StartName = [service name here]
Err.Clear
Set WMI = GetObject("WinMgmts:")
Set oServ = WMI.Get("Win32_Service.Name='" & StartName & "'")
If (Err.number = 0) Then
If (oServ.State = "Running") Then Ret = oServ.StopService
'-- Success if Ret = 0
'do file deletes here....
Ret = oServ.StartService
'-- success if Ret = 0. Error codes listed in WMI help file.
End If
Set oServ = Nothing
Set WMI = Nothing

'----- end VBScript----

If necessary you can change the start mode
while working:

Ret = oServ.ChangeStartMode("disabled")
Ret = oServ.ChangeStartMode("manual")
Ret = oServ.ChangeStartMode("automatic")

You can also check the start mode:

sMode = UCase(oServ.StartMode)
' should return DISABLED, MANUAL or AUTOMATIC

All of that could be built into a single function
that returns a code to let you know whether
it worked and, if not, why.


  #7  
Old December 27th 15, 10:45 PM posted to alt.windows7.general
JJ[_11_]
external usenet poster
 
Posts: 744
Default Issuing 'SC Stop' for service - but waiting until stopped ?

On Sun, 27 Dec 2015 11:37:01 -0500, (PeteCresswell) wrote:
I want to delete a bunch of IP cam output files, but do not want the
.BAT file to hang for such a long time because the cam server
has some files IN USE.

So I want to stop the service, delete the files, and then
re-start the service.

I do not want the service to start automagically while the
delete are in progress.

viz:
================================================== =============
sc stop BlueIris
sc config BlueIris start= disabled

ERASE B:\Alerts\*.* /Q
ERASE B:\Clips \*.* /Q
ERASE B:\Clips_Stored\*.* /Q
ERASE B:\DB\*.* /F /Q

sc start BlueIris
sc config BlueIris start= auto

ECHO OFF
ECHO .
ECHO .
ECHO . ------------ Done! -------------
ECHO .
ECHO .
PAUSE
================================================== ================

It's almost working, but not quite.

According to "Services.msc", the BlueIris service is left in a
"Stopping" state and attempts to re-start it or go at it
via the SC command do not work.

viz:
================================================== ================
C:\BATsc stop BlueIris
[SC] ControlService FAILED 1061:

The service cannot accept control messages at this time.

C:\BATsc config BlueIris start= disabled
[SC] ChangeServiceConfig SUCCESS

C:\BATERASE B:\Alerts\*.* /Q

C:\BATERASE B:\Clips \*.* /Q

C:\BATERASE B:\Clips_Stored\*.* /Q

C:\BATERASE B:\DB\*.* /F /Q

C:\BATsc start BlueIris
[SC] StartService FAILED 1056:

An instance of the service is already running.

C:\BATsc config BlueIris start= auto
[SC] ChangeServiceConfig SUCCESS

C:\BATECHO OFF
.
.
. ------------ Done! -------------
.
.
Press any key to continue . . .
================================================== ================

Am I going at this the wrong way ?


In most cases, a service usually can't be stopped when something is still
using it.

There should be a software that's included by the cam hardware package that
is currently running. It may be like a common windows program that shows the
cam view, or runs in the background and sits on the tray. You may need to
close that software first. It might be the one that give the command to the
service to start the cam recording as well as stop it, gracefully.

If there isn't such software, check the cam's manual about stopping the cam
recording.

If there isn't any, which is the worst case, it means that the service is
supposed to be independent but has design flaw(s) where it can't properly
stop itself. There's one thing you can try. It may work or it may leave the
cam device unusable until the next system reboot (or hard reboot; if there's
also a hardware design flaw).

To stop:
Set the service to "disabled" using SC, then kill the service process using
TASKKILL.

To start:
Using SC, set the service to "demand" or "auto", then start the service.
  #8  
Old December 30th 15, 09:12 PM posted to alt.windows7.general
(PeteCresswell)
external usenet poster
 
Posts: 1,933
Default Issuing 'SC Stop' for service - but waiting until stopped ?

Per (PeteCresswell):
Am I going at this the wrong way ?


FWIW, here is what I have now - and which seems to work.

The main problem I ran in to before this was the Service getting left
in eternal "Stopping" mode - and therefore unreceptive to further
commands or even the Windows UI until the PC was rebooted.

Not so elegant as the other solutions.... but so far, so good.
================================================== =============
:* =====================================
:* PURPOSE:
:* - To take the cam server offline
:* while we delete some of it's files
:*
:* - To delete all of the cam server's
:* Alert, Clip, and DB files
:*
:* - To bring the cam server back online
:* =====================================


:* ------------------------------
:* Kill the BI service

SC STOP BlueIris


:* ------------------------------
:* Wait 5 seconds to give STOP time
:* to do it's thing

CHOICE /N /T 5 /D Y


:* ------------------------------
:* Disable the BI service

SC CONFIG BlueIris START= disabled


:* ------------------------------
:* Wait 5 seconds to give CONFIG time
:* to do it's thing

CHOICE /N /T 5 /D Y


:* ------------------------------
:* Do the deed: Delete Clips and
:* Alerts, delete the Alert DB

ERASE B:\Alerts\*.* /Q
ERASE B:\Clips \*.* /Q
ERASE B:\Clips_Stored\*.* /Q
ERASE B:\DB\*.* /F /Q


:* ------------------------------
:* Re-start the BI service
sc config BlueIris start= auto
sc start BlueIris


ECHO OFF
ECHO .
ECHO .
ECHO . ------------ Done! -------------
ECHO .
ECHO .
PAUSE
================================================== =============
--
Pete Cresswell
  #9  
Old December 31st 15, 04:58 AM posted to alt.windows7.general
Paul
external usenet poster
 
Posts: 18,275
Default Issuing 'SC Stop' for service - but waiting until stopped ?

(PeteCresswell) wrote:
Per (PeteCresswell):
Am I going at this the wrong way ?


FWIW, here is what I have now - and which seems to work.

The main problem I ran in to before this was the Service getting left
in eternal "Stopping" mode - and therefore unreceptive to further
commands or even the Windows UI until the PC was rebooted.

Not so elegant as the other solutions.... but so far, so good.
================================================== =============
:* =====================================
:* PURPOSE:
:* - To take the cam server offline
:* while we delete some of it's files
:*
:* - To delete all of the cam server's
:* Alert, Clip, and DB files
:*
:* - To bring the cam server back online
:* =====================================


:* ------------------------------
:* Kill the BI service

SC STOP BlueIris


:* ------------------------------
:* Wait 5 seconds to give STOP time
:* to do it's thing

CHOICE /N /T 5 /D Y


:* ------------------------------
:* Disable the BI service

SC CONFIG BlueIris START= disabled


:* ------------------------------
:* Wait 5 seconds to give CONFIG time
:* to do it's thing

CHOICE /N /T 5 /D Y


:* ------------------------------
:* Do the deed: Delete Clips and
:* Alerts, delete the Alert DB

ERASE B:\Alerts\*.* /Q
ERASE B:\Clips \*.* /Q
ERASE B:\Clips_Stored\*.* /Q
ERASE B:\DB\*.* /F /Q


:* ------------------------------
:* Re-start the BI service
sc config BlueIris start= auto
sc start BlueIris


ECHO OFF
ECHO .
ECHO .
ECHO . ------------ Done! -------------
ECHO .
ECHO .
PAUSE
================================================== =============


Like Andy Burns suggestion, you can see how
Brink handles a service here.

http://www.tenforums.com/tutorials/2...dows-10-a.html

:wuauserv
net stop wuauserv
echo Checking the wuauserv service status.
sc query wuauserv | findstr /I /C:"STOPPED"
if not %errorlevel%==0 (
goto wuauserv
)

:appidsvc
net stop appidsvc
echo Checking the appidsvc service status.
sc query appidsvc | findstr /I /C:"STOPPED"
if not %errorlevel%==0 (
goto appidsvc
)

I presume the %errorlevel% is coming from the
findstr call. And that being a tight loop,
might use a bit of CPU while it is checking
for the thing being STOPPED.

That code has no timeout in it, so if problems
arise, the user has to press control-C to
stop the script. And use the text of the "echo" line,
to figure out where it got stuck.

Paul
  #10  
Old December 31st 15, 07:48 AM posted to alt.windows7.general
Andy Burns[_3_]
external usenet poster
 
Posts: 399
Default Issuing 'SC Stop' for service - but waiting until stopped ?

(PeteCresswell) wrote:

FWIW, here is what I have now - and which seems to work.


Clearly 5 seconds is better than 0 seconds, but in how many cases does
it need longer to work?

Might be better to disable it *before* stopping it, otherwise it could
get restarted while you're sleeping for the stop to take effect.

  #11  
Old December 31st 15, 03:49 PM posted to alt.windows7.general
David E. Ross[_2_]
external usenet poster
 
Posts: 1,035
Default Issuing 'SC Stop' for service - but waiting until stopped ?

On 12/30/2015 11:48 PM, Andy Burns wrote:
(PeteCresswell) wrote:

FWIW, here is what I have now - and which seems to work.


Clearly 5 seconds is better than 0 seconds, but in how many cases does
it need longer to work?

Might be better to disable it *before* stopping it, otherwise it could
get restarted while you're sleeping for the stop to take effect.


That is why I would use Pause within the script and not merely at the end.

--
David E. Ross

Pharmaceutical companies claim their drug prices are
so high because they have to recover the costs of developing
those drugs. Two questions:

1. Why is the U.S. paying the entire cost of development while
prices for the same drugs in other nations are much lower?

2. Manufacturers of generic drugs did not have those
development costs. Why are they charging so much for generics?
  #12  
Old December 31st 15, 04:44 PM posted to alt.windows7.general
(PeteCresswell)
external usenet poster
 
Posts: 1,933
Default Issuing 'SC Stop' for service - but waiting until stopped ?

Per Andy Burns:
Might be better to disable it *before* stopping it, otherwise it could
get restarted while you're sleeping for the stop to take effect.


Point Taken....

Thanks !
--
Pete Cresswell
  #13  
Old December 31st 15, 04:44 PM posted to alt.windows7.general
Zaidy036[_5_]
external usenet poster
 
Posts: 427
Default Issuing 'SC Stop' for service - but waiting until stopped ?

On 12/31/2015 10:49 AM, David E. Ross wrote:
On 12/30/2015 11:48 PM, Andy Burns wrote:
(PeteCresswell) wrote:

FWIW, here is what I have now - and which seems to work.


Clearly 5 seconds is better than 0 seconds, but in how many cases does
it need longer to work?

Might be better to disable it *before* stopping it, otherwise it could
get restarted while you're sleeping for the stop to take effect.


That is why I would use Pause within the script and not merely at the end.

also consider using
TIMEOUT 5 instead of CHOICE /N /T 5 /D Y
 




Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off






All times are GMT +1. The time now is 08:18 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 PCbanter.
The comments are property of their posters.