Archive: Service and delayed loop


Service and delayed loop
Hello :),

I'm quite a newbie to NSIS and I am trying to check whether the PostgreSQL service is running, in which case I would go ahead and execute a certain piece of code, otherwise I would wait for 1 minute for the process to start, checking every second. Basically it would be a while loop, exit condition being either end of time either the desired process status.


$5 = 0
$6 = 0

PGServiceCheck:

${If} $5 == 60
Goto PGServiceEnd
${EndIf}

SimpleSC::GetServiceStatus "postgresql-8.4"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; return the status of the service (See "service_status" in the parameters)

${If} $0 == 0
$6 = 1
${EndIf}

${If} $6 == 1
Goto PGServiceEnd
${EndIf}

IntOp $5 $5 + 1
Sleep 1000

PGServiceEnd:



I would really like to know if this is the/a correct approach.

Thanks in advance,

Brad

New to programming in general? :)

${For} $R0 1 60
SimpleSC::GetServiceStatus "postgresql-8.4"
Pop $R1
Pop $R2
${If} $R1 == 0
${AndIf} $R2 == 4 ; SERVICE_RUNNING
${Break}
${EndIf}
Sleep 1000
${Next}
You haven't thought about an action to take if the service is never started. You could have this after the loop:
${If} $R0 == 61
# handle error
#
Abort
${EndIf}
Stu

Hey! big thanks! :) ... Unfortunately I'm not new to programming, just very tired to look up all the statements, instructions and functions I needed when I wrote the installer.

This was everything I knew of the GetServiceStatus


; Get the current status of a service
SimpleSC::GetServiceStatus "MyService"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; return the status of the service (See "service_status" in the parameters)

so for some reason I assumed that it returns 1 in $0 when status is running and anything else if it fails, popping the info in $1. Basically I get a 0 in $0 when I get a status from the service and it pops a 4 in $1 if the status is running.
Also, now I know how the for statement looks like :D, and of course a for or a while is the best choice for this.

In case I get out after 60 seconds I wont execute the code that follows, but that I didn't include that in the present code. As a matter of fact I forgot some things in the code I wrote (the jump backwards) so I can see why you assumed I was new to programming ^^


Anyway, big thanks :)