Trying to wait for a service to stop

View: New views
3 Messages — Rating Filter:   Alert me  

Trying to wait for a service to stop

by Gary Kuznitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm trying to:
stop a service in XP
Loop Checkig it's status until it stops
copy a new program for starting the service
copy a new program for viewing
starting the service

I'm getting an error saying:
The process cannot access the file because it is being used by another process.
        0 file(s) copied.
        1 file(s) copied.
The uvnc_service service is starting.
The uvnc_service service was started successfully.

The bat file I am using to try to do this (which isn't working) is:
setlocal enabledelayedexpansion
net stop UVNC_service >nul
for %%a in ("UVNC_service") do call :GETSRVSTAT %%a&if /i not
"!status!"=="Running" goto :COPY
echo All services are running...
goto :COPY
:GETSRVSTAT
set status=
for /f "tokens=4" %%a in ('sc query "%~1" 2^>NUL^|findstr STATE') do set
status=%%a

:COPY
copy /y "%PATH_BIN%winvnc.exe" "%programfiles%\UltraVNC"
copy /y "%PATH_BIN%vncviewer.exe" "%programfiles%\UltraVNC"
start /d "%programfiles%\UltraVNC" winvnc.exe -servicehelper"
net start UVNC_service
::exit
CMD

Any idea what I am doing wrong?

Thank you,

Gary Kuznitz



Re: Trying to wait for a service to stop

by foxidrive-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 27 May 2008 21:26:55 -0700, "Gary Kuznitz" <docfxit@...>
wrote:

>I'm trying to:
>stop a service in XP
>Loop Checkig it's status until it stops
>copy a new program for starting the service
>copy a new program for viewing
>starting the service
>
>I'm getting an error saying:
>The process cannot access the file because it is being used by another process.
>        0 file(s) copied.
>        1 file(s) copied.
>The uvnc_service service is starting.
>The uvnc_service service was started successfully.
>
>The bat file I am using to try to do this (which isn't working) is:
>setlocal enabledelayedexpansion
>net stop UVNC_service >nul

Both the below options will goto :COPY

>for %%a in ("UVNC_service") do call :GETSRVSTAT %%a&if /i not
>"!status!"=="Running" goto :COPY
>echo All services are running...
>goto :COPY

>:GETSRVSTAT
>set status=
>for /f "tokens=4" %%a in ('sc query "%~1" 2^>NUL^|findstr STATE') do set
>status=%%a

and after the above routine it will fall through to :COPY as well.

>:COPY
>copy /y "%PATH_BIN%winvnc.exe" "%programfiles%\UltraVNC"
>copy /y "%PATH_BIN%vncviewer.exe" "%programfiles%\UltraVNC"

There's are errors in the following line it seems

>start /d "%programfiles%\UltraVNC" winvnc.exe -servicehelper"
>net start UVNC_service
>::exit
>CMD
>

This might help (untested)

setlocal
net stop UVNC_service >nul
:loop
echo waiting for the service to stop
ping -n 10 127.0.0.1 >nul
net start|find /i "UVNC_service">nul&&goto :loop
if not exist "%programfiles%\UltraVNC\" md "%programfiles%\UltraVNC"
copy /y "%PATH_BIN%winvnc.exe" "%programfiles%\UltraVNC" >nul
copy /y "%PATH_BIN%vncviewer.exe" "%programfiles%\UltraVNC" >nul
start "" "%programfiles%\UltraVNC\winvnc.exe" -servicehelper
ping -n 10 127.0.0.1 >nul
net start UVNC_service




Re: Trying to wait for a service to stop

by Gary Kuznitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you Foxidrive,

That worked great.  It's so nice to have a way to do things like this.

Thank you,

Gary Kuznitz



On 28 May 2008 at 15:14, foxidrive (foxidrive <batchworld@...>) commented about Re: [BATCH WORLD] Trying to wait for a service to:

> On Tue, 27 May 2008 21:26:55 -0700, "Gary Kuznitz" <docfxit@...>
> wrote:
>
> >I'm trying to:
> >stop a service in XP
> >Loop Checkig it's status until it stops
> >copy a new program for starting the service
> >copy a new program for viewing
> >starting the service
> >
> >I'm getting an error saying:
> >The process cannot access the file because it is being used by another process.
> >        0 file(s) copied.
> >        1 file(s) copied.
> >The uvnc_service service is starting.
> >The uvnc_service service was started successfully.
> >
> >The bat file I am using to try to do this (which isn't working) is:
> >setlocal enabledelayedexpansion
> >net stop UVNC_service >nul
>
> Both the below options will goto :COPY
>
> >for %%a in ("UVNC_service") do call :GETSRVSTAT %%a&if /i not
> >"!status!"=="Running" goto :COPY
> >echo All services are running...
> >goto :COPY
>
> >:GETSRVSTAT
> >set status=
> >for /f "tokens=4" %%a in ('sc query "%~1" 2^>NUL^|findstr STATE') do set
> >status=%%a
>
> and after the above routine it will fall through to :COPY as well.
>
> >:COPY
> >copy /y "%PATH_BIN%winvnc.exe" "%programfiles%\UltraVNC"
> >copy /y "%PATH_BIN%vncviewer.exe" "%programfiles%\UltraVNC"
>
> There's are errors in the following line it seems
>
> >start /d "%programfiles%\UltraVNC" winvnc.exe -servicehelper"
> >net start UVNC_service
> >::exit
> >CMD
> >
>
> This might help (untested)
>
> setlocal
> net stop UVNC_service >nul
> :loop
> echo waiting for the service to stop
> ping -n 10 127.0.0.1 >nul
> net start|find /i "UVNC_service">nul&&goto :loop
> if not exist "%programfiles%\UltraVNC\" md "%programfiles%\UltraVNC"
> copy /y "%PATH_BIN%winvnc.exe" "%programfiles%\UltraVNC" >nul
> copy /y "%PATH_BIN%vncviewer.exe" "%programfiles%\UltraVNC" >nul
> start "" "%programfiles%\UltraVNC\winvnc.exe" -servicehelper
> ping -n 10 127.0.0.1 >nul
> net start UVNC_service

LightInTheBox - Buy quality products at wholesale price