Jump to content
Sign in to follow this  
iceberg

Shorter Script?

Recommended Posts

iceberg

hi guys,

appreciate if the following script could be simplified. and also, need some advice as to why line 25 doesn't work.

thanks.

#include <ServiceControl.au3>

Global $sServiceName, $State
Global $sComputerName = "."
Global $ini = @ScriptDir & "\settings.ini"
Global $svc = IniReadSection($ini, "services")
Dim $nRet
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""

For $p = 1 To $svc[0][0]
    $sServiceName = $svc[$p][0]
    Exists()
Next

Func Exists()
    $nRet = _ServiceExists($sComputerName, $sServiceName)
    If $nRet Then
        $objWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\CIMV2")
        $colItems = $objWMIService.ExecQuery("Select * from Win32_Service where displayname = '" & $sServiceName & "'", "WQL", _
                $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
        For $objItem In $colItems
            $State = $objItem.State
            IniWrite($ini, "services", $sServiceName, $State)
            If $State <> "Running" Then Page()
        Next
    Else
        Page2()
    EndIf
EndFunc  ;==>Exists

Func Page()
    $page = IniReadSection($ini, "PageList")
    For $i = 1 To $page[0][0]
        MsgBox(4096, "Paging " & $page[$i][1], @ComputerName & ": " & $sServiceName & " " & $State)
    Next
EndFunc  ;==>Page

Func Page2()
    $page = IniReadSection($ini, "PageList")
    For $j = 1 To $page[0][0]
        MsgBox(4096, "Paging " & $page[$j][1], @ComputerName & ": " & $sServiceName & " does not exists.")
        IniWrite($ini, "services", $sServiceName, "NON-EXISTENT")
    Next
EndFunc  ;==>Page2

mouse not found....scroll any mouse to continue.

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.