Jump to content

Recommended Posts

Posted
Guess this will be my first countribute for examples scripts

This may come handy for some people one day
Func _GetServicesList() ;[0][0] Services Count, [x][0] Service name, [x][1] Service State
    Local $iExitCode, $st,$a,$aServicesList[1][2],$x
    $iExitCode = Run(@ComSpec & ' /C sc queryex type= service state= all', '', @SW_HIDE, 0x2)
    While 1
        $st &= StdoutRead($iExitCode)
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    $a = StringRegExp($st,'(?m)(?i)(?s)(?:SERVICE_NAME|NOME_SERVI€O)\s*?:\s+?(\w+).+?(?:STATE|ESTADO)\s+?:\s+?\d+?\s+?(\w+)',3)
    For $x = 0 To UBound($a)-1 Step 2
        ReDim $aServicesList[UBound($aServicesList)+1][2]
        $aServicesList[UBound($aServicesList)-1][0]=$a[$x]
        $aServicesList[UBound($aServicesList)-1][1]=$a[$x+1]
    Next
    $aServicesList[0][0]=UBound($aServicesList)-1
    Return $aServicesList
EndFunc 

Exemple usage (for starters)

#include <Array.au3> ;You need this only for _arrayDisplay
Local $aServ
$aServ = _GetServicesList()
_ArrayDisplay($aServ)
Exit

I only seek for the service state since is the only thing I needed, adding other stuff only will take more time for the function run, but I can give a hand on that if you need it.

PS: Works 100% on EN/PT language, other languages need stdout text further evaluation...

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

  • 3 weeks later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...