Jump to content

Shorter Script?


Recommended Posts

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

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