Sign in to follow this  
Followers 0
RvdH

Check if service is running

18 posts in this topic

Is there a way i can check if a Windows Service, like Network Support is started before an auto-it app launches?

RvdH

Share this post


Link to post
Share on other sites



hello everyone

i am very interested in the same question. i've done searches till i'm blue in the face and all i come up with is quote

If you have sc.exe in your system directory:

CODE sc query "servicename" i have no idea how to use that!

phil

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

See here:

http://www.autoitscript.com/forum/index.php?showtopic=20001

Edit:

That post has a script that uses "Net Start" and another script that uses SC.exe....

(and then there is the WMI method that can be found in other posts)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

hello everyone

i am very interested in the same question. i've done searches till i'm blue in the face and all i come up with is quote

If you have sc.exe in your system directory:

CODE sc query "servicename" i have no idea how to use that!

phil

In CMD prompt if you type Net Start Workstation

It tells you if the service is already started, I don't know any other way of doing it myself though

Share this post


Link to post
Share on other sites

@herewasplato

thank you! i don't think i'll ever figure out the search function on this great forum.

phil

Share this post


Link to post
Share on other sites

@herewasplato

thank you! i don't think i'll ever figure out the search function on this great forum.

phil

You are welcome...

RvdH,

Did the code in that post work for you or do you need more info on the topic?

...and BTW, welcome to the forum!


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

SC.exe seems to only return Running services upon query, so the below code should be sufficient. This does use StdOutRead() from the AutoIt Beta.

$stdout = Run('sc.exe query ' & $servicename, '', @SW_HIDE, 2)
$data = _StdOut($stdout)

Func _StdOut($stdout)
    Local $data
    While 1
        $data = StdOutRead($stdout)
        If @error Then Return 'unknown'
        If $data Then
            If StringInStr($data, 'Running') Then Return 'Running'
        Else
            Sleep(10)   
        EndIf
    WEnd
EndFunc

MsgBox(0, '', $data)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks 4 all your replies, seems i succesfully managed to determine the service state :lmao:

@herewasplato,

i'm using the 2e (beta) example in that topic you posted, have to check if latest reply from MHz's way of doing it will work also

Btw in the beta example from the other post the are 4 return codes, (1,2,3,4 where 4 is running) can you tell me the other values?

Thx!

RvdH

Edited by RvdH

Share this post


Link to post
Share on other sites

Btw in the beta example from the other post the are 4 return codes, (1,2,3,4 where 4 is running) can you tell me the other values?

I'm not sure and I did not find a webpage that explains those states. You'll have to ask MHz - but I think that what he posted to this thread is just a better version of what he posted to the other thread: http://www.autoitscript.com/forum/index.ph...ndpost&p=138576

In that other thread, MHz states:

Edit: But perhaps searching for the string Running etc, would be more correct as the numbers would be the state for service startup, hmm.

That is what he did in the code in this thread - searched for the word "running" in the output of the sc query...

A little experimenting gives me 1 and 4:

(and then there is 7)

SERVICE_NAME: wzcsvc

TYPE : 20 WIN32_SHARE_PROCESS

STATE : 1 STOPPED

(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)

WIN32_EXIT_CODE : 0 (0x0)

SERVICE_EXIT_CODE : 0 (0x0)

CHECKPOINT : 0x0

WAIT_HINT : 0x0

c:\>sc query wzcsvc

SERVICE_NAME: wzcsvc

TYPE : 20 WIN32_SHARE_PROCESS

STATE : 4 RUNNING

(STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)

WIN32_EXIT_CODE : 0 (0x0)

SERVICE_EXIT_CODE : 0 (0x0)

CHECKPOINT : 0x0

WAIT_HINT : 0x0

SERVICE_NAME: ShellHWDetection

TYPE : 20 WIN32_SHARE_PROCESS

STATE : 7 PAUSED

(STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN)

WIN32_EXIT_CODE : 0 (0x0)

SERVICE_EXIT_CODE : 0 (0x0)

CHECKPOINT : 0x0

WAIT_HINT : 0x0

later....

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Ah, ok thx...

another quick question though... can 2 If/Else/Endif statement be mixed with auto-it?

My current script is not functioning after adding a 2e If/Else/Endif statement

Like:

If {this1} Then
   If {this2} Then
   Else
    Exit
   End if
Else
  Exit
End If

RvdH

Edited by RvdH

Share this post


Link to post
Share on other sites

Ah, ok thx...

another quick question though... can 2 if, else, endif statement be mixed with auto-it?

Like:

If {this1} Then
   If {this2} Then
   Else
    Exit
   End if
Else
  Exit
End If

RvdH

yes

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

yes

Thats a quick answer as well :lmao:...but it doesn't fix the issue i having

[Edit] Can someone see whats wrong with the post below?

Edited by RvdH

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

edited, look furter below

Edited by RvdH

Share this post


Link to post
Share on other sites

Had to download beta and the latest SciTE/Updates - via dialup no less.

It works for me up to here:

If StringInStr($data, 'Running') Then

What exactly is it not doing for you...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

When the "Tcpip" service is checked and running the script works OK

but whenever the "Tcpip" service is not running it popups the $answer MsgBox, After choosing "Yes" where the service should be started the executable just stops, allthough the code posted below should be executed...so either the program should be started or the MsgBox should popup...none of this happens

btw, don't know if it matters but i'm using "v3.1.1.102" (shall try with latest build now)

If FileExists(@SystemDir & "\BartPE.exe") Then
            RunWait(@ComSpec & " /c bartpe.exe -c p -i ms_tcpip", "", @SW_HIDE) 
            RunWait(@ComSpec & " /c bartpe.exe -c c -i ms_msclient", "", @SW_HIDE)
            RunWait(@ComSpec & " /c " & 'net start "tcpip"', "", @SW_HIDE)
            RunWait(@ComSpec & " /c " & 'net start "dhcp"', "", @SW_HIDE)
            RunWait(@ComSpec & " /c regsvr32 /s /i ""%SystemDrive%\Programs\OO Software\Defrag Professional\oodpeo.ocx", "", @SW_HIDE)
            RunWait(@SystemDir & "\oodag.exe /service")
            RunWait(@ComSpec & " /c " & 'net start "O&O Defrag"', "", @SW_HIDE)
            RunWait($systemdrive & "\Programs\OO Software\Defrag Professional\oodcntrun.exe")
            RunWait(@ComSpec & " /c regsvr32 /s /u ""%SystemDrive%\Programs\OO Software\Defrag Professional\oodpeo.ocx", "", @SW_HIDE)
            RunWait(@SystemDir & "\oodag.exe /uninstall")
            RunWait(@ComSpec & " /c " & 'net stop "O&O Defrag"', "", @SW_HIDE)
     Exit
        Else
            MsgBox(48, "O&O Defrag Professional", "Bartpe.exe could not be found, O&O Defrag needs this file to start required services!")
            Exit
        Endif
Edited by RvdH

Share this post


Link to post
Share on other sites

Same result with Beta v3.1.1.103... :lmao:

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

change

If $answer = 1 Then

to

If $answer = 6 Then

...let me know...

edit: yes = 6

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Whoohoo, yes, that did it !

Thx, never could have find this on my own...

RvdH

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  
Followers 0