Jump to content
Sign in to follow this  
Jass

Wait until Service is stopped before continuing script

Recommended Posts

Jass

Hey all,

I wrote a script to backup a MS SQL database and some files to another directory.

My question is how is it possible to wait until the MS SQL service is stopped before continuing the script and copying the database and the other files.

I tried to realize this with a while loop but i doesn't work.

This is the part of the script which doesn't want to work as I want it to:

;Shutdown SQL-Server
_RunDOS("sc stop " & $sqlinstancename)

$statusservice = _Service_QueryStatus($sqlinstancename)
While $statusservice[1] <> 1
 Sleep(5000)
WEnd

For the function _Service_QueryStatus I use the UDF Services.au3, the function returns 1 for Array[1] if service is stopped. If Service isn't stopped I want the script to wait five seconds until rechecking the state.

But this doesn't work :)

Thanks for help.

Jass

Edited by Jass

Share this post


Link to post
Share on other sites
Juvigy

The easiest i can thing of is to use RunWait to stop the service .

@edit

Scratch that it doesnt work - the CMD command doesnt wait until the service is stopped to complete and exit.

Edited by Juvigy

Share this post


Link to post
Share on other sites
99ojo

Hi,

you have to refresh the $statusservice in between the While loop, otherwise it won't change and loop for ever:

$statusservice = _Service_QueryStatus($sqlinstancename)
While $statusservice[1] <> 1
   Sleep(5000)
   $statusservice = _Service_QueryStatus($sqlinstancename)
WEnd

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
Jass

Hi,

you have to refresh the $statusservice in between the While loop, otherwise it won't change and loop for ever:

;-))

Stefan

Great!

Thanks man und schöne Grüße nach Bonn :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.