Sign in to follow this  
Followers 0
GEOSoft

Windows Services UDF

101 posts in this topic

#1 ·  Posted (edited)

This is pretty basic so I'm not including examples just yet. Just #include the enclosed services.au3 file.

Edit;

Attachment removed. Download from

Services.zip

Edit 2;

Code Removed. Use the link to my web site (in my signature), click on Code >> My Extra UDFs >> Services.au3

Updated functions.

Edit 3: May 16/ 2008

Updated to add impersonation level to most functions for better control of remote services.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites



Thanks Geo, I think that's the third handy post I've found from you in less than a minute. I appreciate the classid/control panel reference posts too.

I could have put your service script to the true test last week when I was still running Vista. Criminy! Have you checked it out yet? Gee, I don't know how I ever got by in XP without "Infared Casio Keyboard Lan Sync Agent For Atari 2600 Datalink Consoles" running in the background. :whistle:

Just in case you hadn't considered it; one of the tweak utilities that I use allows you to save and load service profiles on the fly. That's pretty handy for quickly killing all but ___ for installs or firing up ___ when something might be a little risky.

Thanks again.

Share this post


Link to post
Share on other sites

Just in case you hadn't considered it; one of the tweak utilities that I use allows you to save and load service profiles on the fly. That's pretty handy for quickly killing all but ___ for installs or firing up ___ when something might be a little risky.

Thanks again.

Thanks for the reply. _servKillAll will probably end up in a later version. Actually I could have made this version twice as long but first I want to see the response to these functions' If enough people will use them then I'll add some more. As for Vista (aka The Great Mistake), I'm not even attempting to write code that works with it, if it works it works. I have a Vista install in a VPC environment but the less I use it the happier I am.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I have added some more functions to this UDF. I did not write these functions I just am compiling and documenting these.

Global $STANDARD_RIGHTS_REQUIRED = 0x000F0000
Global $SC_MANAGER_CONNECT = 0x0001
Global $SC_MANAGER_CREATE_SERVICE = 0x0002
Global $SC_MANAGER_ENUMERATE_SERVICE = 0x0004
Global $SC_MANAGER_LOCK = 0x0008
Global $SC_MANAGER_QUERY_LOCK_STATUS = 0x0010
Global $SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020

Global $SC_MANAGER_ALL_ACCESS = BitOR($STANDARD_RIGHTS_REQUIRED, _
                                     $SC_MANAGER_CONNECT, _
                                     $SC_MANAGER_CREATE_SERVICE, _
                                     $SC_MANAGER_ENUMERATE_SERVICE, _
                                     $SC_MANAGER_LOCK, _
                                     $SC_MANAGER_QUERY_LOCK_STATUS, _
                                     $SC_MANAGER_MODIFY_BOOT_CONFIG)
                                   
Global $SERVICE_QUERY_CONFIG = 0x0001
Global $SERVICE_CHANGE_CONFIG = 0x0002
Global $SERVICE_QUERY_STATUS = 0x0004
Global $SERVICE_ENUMERATE_DEPENDENTS = 0x0008
Global $SERVICE_START = 0x0010
Global $SERVICE_STOP = 0x0020
Global $SERVICE_PAUSE_CONTINUE = 0x0040
Global $SERVICE_INTERROGATE = 0x0080
Global $SERVICE_USER_DEFINED_CONTROL = 0x0100

Global $SERVICE_ALL_ACCESS = BitOR($STANDARD_RIGHTS_REQUIRED, _
                                  $SERVICE_QUERY_CONFIG, _
                                  $SERVICE_CHANGE_CONFIG, _
                                  $SERVICE_QUERY_STATUS, _
                                  $SERVICE_ENUMERATE_DEPENDENTS, _
                                  $SERVICE_START, _
                                  $SERVICE_STOP, _
                                  $SERVICE_PAUSE_CONTINUE, _
                                  $SERVICE_INTERROGATE, _
                                  $SERVICE_USER_DEFINED_CONTROL)

Global $SERVICE_CONTROL_STOP = 0x00000001
Global $SERVICE_CONTROL_INTERROGATE = 0x00000004

#comments-start***
Example - stop print spooler service
If _ServiceRunning("Spooler") Then
  _StopService("Spooler")
  If @error Then
     MsgBox(64, "", "Failed to stop Spooler service")
  Else
     MsgBox(64, "", "Spooler service stopped")
  EndIf
Else
  _StartService("Spooler")
  If @error Then
     MsgBox(64, "", "Failed to start Spooler service")
  Else
     MsgBox(64, "", "Spooler service started")
  EndIf  
EndIf
#comments-end***

;===============================================================================
;
; Description:      Starts a service
; Syntax:           _StartService($sServiceName)
; Parameter(s):     $sServiceName - Name of service to start
; Requirement(s):   None
; Return Value(s):  On Success - Sets   @error = 0
;                   On Failure - Sets:
;                                       @error = 1056: Already running
;                                       @error = 1060: Service does not exist
; Author(s):        SumTingWong
; Documented by:    noone
;
;===============================================================================
Func _StartService($sServiceName)
  Local $arRet
  Local $hSC
  Local $hService
  Local $lError = -1

  $arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
                   "str", "", _
                   "str", "ServicesActive", _
                   "long", $SC_MANAGER_CONNECT)
  If $arRet[0] = 0 Then
     $arRet = DllCall("kernel32.dll", "long", "GetLastError")
     $lError = $arRet[0]
  Else
     $hSC = $arRet[0]
     $arRet = DllCall("advapi32.dll", "long", "OpenService", _
                      "long", $hSC, _
                      "str", $sServiceName, _
                      "long", $SERVICE_START)
     If $arRet[0] = 0 Then
        $arRet = DllCall("kernel32.dll", "long", "GetLastError")
        $lError = $arRet[0]
     Else
        $hService = $arRet[0]
        $arRet = DllCall("advapi32.dll", "int", "StartService", _
                         "long", $hService, _
                         "long", 0, _
                         "str", "")
        If $arRet[0] = 0 Then
           $arRet = DllCall("kernel32.dll", "long", "GetLastError")
           $lError = $arRet[0]
        EndIf
        DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)        
     EndIf
     DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
  EndIf
  If $lError <> -1 Then SetError($lError)
EndFunc


;===============================================================================
;
; Description:      Stops a service
; Syntax:           _StopService($sServiceName)
; Parameter(s):     $sServiceName - Name of service to stop
; Requirement(s):   None
; Return Value(s):  On Success - Sets:  
;                                       @error = 0
;                   On Failure - Sets:
;                                       @error = 1062: Already stopped
;                                       @error = 1060: Service does not exist
; Author(s):        SumTingWong
; Documented by:    noone
;
;===============================================================================
Func _StopService($sServiceName)
  Local $arRet
  Local $hSC
  Local $hService
  Local $lError = -1

  $arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
                   "str", "", _
                   "str", "ServicesActive", _
                   "long", $SC_MANAGER_CONNECT)
  If $arRet[0] = 0 Then
     $arRet = DllCall("kernel32.dll", "long", "GetLastError")
     $lError = $arRet[0]
  Else
     $hSC = $arRet[0]
     $arRet = DllCall("advapi32.dll", "long", "OpenService", _
                      "long", $hSC, _
                      "str", $sServiceName, _
                      "long", $SERVICE_STOP)
     If $arRet[0] = 0 Then
       $arRet = DllCall("kernel32.dll", "long", "GetLastError")
       $lError = $arRet[0]
     Else
        $hService = $arRet[0]
        $arRet = DllCall("advapi32.dll", "int", "ControlService", _
                         "long", $hService, _
                         "long", $SERVICE_CONTROL_STOP, _
                         "str", "")
        If $arRet[0] = 0 Then
           $arRet = DllCall("kernel32.dll", "long", "GetLastError")
           $lError = $arRet[0]
        EndIf
        DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)        
     EndIf
     DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
  EndIf
  If $lError <> -1 Then SetError($lError)
EndFunc

;===============================================================================
;
; Description:      Checks to see if a service is installed
; Syntax:           _ServiceExists($sServiceName)
; Parameter(s):     $sServiceName - Name of service to check
; Requirement(s):   None
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
; Author(s):        SumTingWong
; Documented by:    noone
;
;===============================================================================
Func _ServiceExists($sServiceName)
  Local $arRet
  Local $hSC
  Local $bExist = 0
 
  $arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
                   "str", "", _
                   "str", "ServicesActive", _
                   "long", $SC_MANAGER_CONNECT)
  If $arRet[0] <> 0 Then
     $hSC = $arRet[0]
     $arRet = DllCall("advapi32.dll", "long", "OpenService", _
                      "long", $hSC, _
                      "str", $sServiceName, _
                      "long", $SERVICE_INTERROGATE)
     If $arRet[0] <> 0 Then
        $bExist = 1
        DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $arRet[0])
     EndIf
     DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
  EndIf
  Return $bExist
EndFunc

;===============================================================================
;
; Description:      Checks to see if a service is running
; Syntax:           _ServiceRunning($sServiceName)
; Parameter(s):     $sServiceName - Name of service to check
; Requirement(s):   None
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
; Author(s):        SumTingWong
; Documented by:    noone
;
;===============================================================================
Func _ServiceRunning($sServiceName)
  Local $arRet
  Local $hSC
  Local $hService  
  Local $bRunning = 0

  $arRet = DllCall("advapi32.dll", "long", "OpenSCManager", _
                   "str", "", _
                   "str", "ServicesActive", _
                   "long", $SC_MANAGER_CONNECT)
  If $arRet[0] <> 0 Then
     $hSC = $arRet[0]
     $arRet = DllCall("advapi32.dll", "long", "OpenService", _
                     "long", $hSC, _
                     "str", $sServiceName, _
                     "long", $SERVICE_INTERROGATE)
     If $arRet[0] <> 0 Then
        $hService = $arRet[0]
        $arRet = DllCall("advapi32.dll", "int", "ControlService", _
                         "long", $hService, _
                         "long", $SERVICE_CONTROL_INTERROGATE, _
                         "str", "")
        $bRunning = $arRet[0]
        DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hService)
     EndIf
     DllCall("advapi32.dll", "int", "CloseServiceHandle", "long", $hSC)
  EndIf
  Return $bRunning
EndFunc

;===============================================================================
; Description:   Delete a Windows Service
; Syntax:   _ServDelete($iName[, $Computer])
; Parameter(s):   $iName - The name of the service to delete
;                            $Computer - The network name of the computer (optional) The local computer is default
; Requirement(s):   None
; Return Value(s):   Success - Deletes the service
;                                Failure Sets @Error = -1 if service is not found
; Author(s)   GEOSoft
; Modification(s):   
; Note(s):   
; Example(s):   
;===============================================================================

Func _ServDelete($iName, $Computer = ".")
    $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service")
    For $objService in $sItems
        If $objService.Name == $iName Then
            $objService.StopService($objService.Name)
            $objService.Delete($objService.Name)
            Return
        EndIf
    Next
    Return SetError(-1)
EndFunc   ;<==> _ServDelete()

;===============================================================================
; Description:   Return the details of a Windows Service
; Syntax:   _ServGetDetails($iName[, $Computer])
; Parameter(s):   $iName - The name of the service to check
;                            $Computer - The network name of the computer (optional) The local computer is default
; Requirement(s):   None
; Return Value(s):   Success - Returns an array of the service details where element (-1 = Yes, 0 = No)
;                                    [1] = Computer Network Name
;                                    [2] = Service Name
;                                    [3] = Service Type (Own Process, Share Process)
;                                    [4] = Service State (Stopped, Running, Paused)
;                                    [5] = Exit Code (0, 1077)
;                                    [6] = Process ID
;                                    [7] = Can Be Paused (-1, 0)
;                                    [8] = Can Be Stopped (-1, 0)
;                                    [9] = Caption
;                                    [10] = Description
;                                    [11] = Can Interact With Desktop (-1, 0)
;                                    [12] = Display Name
;                                    [13] = Error Control (Normal, Ignore)
;                                    [14] = Executable Path Name
;                                    [15] = Service Started (-1, 0)
;                                    [16] = Start Mode (Auto, Manual, Disabled)
;                                    [17] = Account Name (LocalSystem, NT AUTHORITY\LocalService, NT AUTHORITY\NetworkService)
;                                Failure Sets @Error = -1 if service not found
; Author(s)   GEOSoft
; Modification(s):   
; Note(s):   
; Example(s):   $Var = _ServGetDetails("ATI Smart")
;                         $Dtl = "System Name|Name|Type|State|ExitCode|Process ID|Can Pause|Can Stop|Caption|Description|"
;                         $Dtl = StringSplit($Dtl & "Interact With DskTop|Display Name|Error Control|Exec File Path|Started|Start Mode|Account", '|')
;                         For $I = 1 To $Var[0]
;                         MsgBox(4096,$Dtl[$I], $Var[$I])
;                         Next
;===============================================================================

Func _ServGetDetails($iName, $Computer = ".")
    Local $Rtn = ''
    $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service")
    For $objService in $sItems
        If $objService.Name == $iName Then
        $Rtn &= $objService.SystemName & '|' & $objService.Name & '|' & $objService.ServiceType & '|' & $objService.State & '|'
        $Rtn &= $objService.ExitCode & '|' & $objService.ProcessID & '|' & $objService.AcceptPause & '|' & $objService.AcceptStop & '|'
        $Rtn &= $objService.Caption & '|' & $objService.Description & '|' & $objService.DesktopInteract & '|' & $objService.DisplayName & '|'
        $Rtn &= $objService.ErrorControl & '|' & $objService.PathName & '|' &$objService.Started & '|' & $objService.StartMode & '|'
        $Rtn &= $objService.StartName
        Return StringSplit($Rtn, '|')
        EndIf
    Next
    Return SetError(-1)
EndFunc

;===============================================================================
; Description:   Return the current state of a Windows Service
; Syntax:   _ServGetState($iName[, $Computer])
; Parameter(s):   $iName - The name of the service to check
;                            $Computer - The network name of the computer (optional) The local computer is default
; Requirement(s):   None
; Return Value(s):   Success - Returns the state of the service
;                                Failure Sets @Error = -1 if service not found
; Author(s)   GEOSoft
; Modification(s):   
; Note(s):   
; Example(s):   
;===============================================================================

Func _ServGetState($iName, $Computer = ".")
    $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service")
    For $objItem in $sItems
        If $objItem.Name == $iName Then Return $objItem.State
    Next
    Return SetError(-1)
EndFunc   ;<==> _ServGetState()

;===============================================================================
; Description:   List the currently installed services
; Syntax:   _ServListInstalled([,$Computer])
; Parameter(s):   $Computer - The network name of the computer (optional) The local computer is default
; Requirement(s):   None
; Return Value(s):   Success - Returns the state of the service
;                                Failure Sets @Error = -1 if service not found
; Author(s)   GEOSoft
; Modification(s):   
; Note(s):   
; Example(s):   
;===============================================================================

Func _ServListInstalled($Computer = ".")
    Local $Rtn = ''
    $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service")
    For $objService in $sItems
        $Rtn &= $objService.Name & '|'
    Next
    Return StringSplit(StringTrimRight($Rtn, 1), '|')
EndFunc

;===============================================================================
; Description:   Pause a Windows Service
; Syntax:   _ServPause($iName[, $Computer])
; Parameter(s):   $iName - The name of the service to start
;                            $Computer - The network name of the computer (optional). The local computer is default
; Requirement(s):   None
; Return Value(s):   Success - Pauses the service
;                                Failure Sets @Error = -1 if service not found or service is already paused
; Author(s)   GEOSoft
; Modification(s):   
; Note(s):   
; Example(s):   
;===============================================================================

Func _ServPause($iName, $Computer = ".")
    $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service Where State = 'Running' ")
    For $objService in $sItems
        If $objService.Name == $iName Then
            $objService.PauseService($objService.Name)
            Return
        EndIf
    Next
    Return SetError(-1)
EndFunc   ;<==> _ServPause()

;===============================================================================
; Description:   Resumes a  previously paused Windows auto-start service
; Syntax:   _ServResume($iName[, $Computer])
; Parameter(s):   $iName - The name of the service to start
;                            $Computer - The network name of the computer (optional). The local computer is default
; Requirement(s):   None
; Return Value(s):   Success - Resumes the service
;                                Failure Sets @Error = -1 if service not found
; Author(s)   GEOSoft
; Modification(s):   
; Note(s):   
; Example(s):   
;===============================================================================

Func _ServResume($iName, $Computer = ".")
    $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
    $sItems = $Service.ExecQuery("Select * from Win32_Service Where State = 'Paused' and StartMode = 'Auto'")
    For $objService in $sItems
        If $objService.Name == $iName Then
            $objService.ResumeService($objService.Name)
            Return
        EndIf
    Next
    Return SetError(-1)
EndFunc   ;<==> _ServResume()

Share this post


Link to post
Share on other sites

Thanks a lot @noone

I've added them to mine and I'll be posteing a ip file soon with the the complete UDF


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thanks a lot @noone

I've added them to mine and I'll be posteing a ip file soon with the the complete UDF

I was missing one little thing in all those posts about service managing so i wrote this little one. If you can/want add it to the service managing on first post or so.

MsgBox(0, "Test", _ServiceStartType("Carboncopy32", "Disabled"))

;===============================================================================
; Description:   Sets StartType of a service on a computer
; Author:        MadBoy
; Parameters:    $sComputerName - name of the target computer. If empty, the local computer name is used
;                 $sStatus - status of the service to set. Possible options are "Auto", "Manual", "Disabled".
;                $sServiceName - name of the service to set start type for
; Requirements:  None
; Return Values: On Success - 1
;                On Failure - 0
; Note:          This function does not stop/start service.
;===============================================================================
Func _ServiceStartType($sServiceName, $sStatus, $sComputerName = "")
    Local $iValue
    Local $sServiceKeyPath = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\" & $sServiceName

    If $sStatus = "Auto" Then $iValue = "2"
    If $sStatus = "Manual" Then $iValue = "3"
    If $sStatus = "Disabled" Then $iValue = "4"
    
    If $sComputerName = "" Then
        If RegRead($sServiceKeyPath, "Start") <> "" Then
            If RegWrite($sServiceKeyPath, "Start", "REG_DWORD", $iValue) = 1 Then Return 1
        Else
            Return 0
        EndIf
    Else
        If RegRead("\\" & $sComputerName & "\" & $sServiceKeyPath, "Start") <> "" Then
            If RegWrite("\\" & $sComputerName & "\" & $sServiceKeyPath, "Start", "REG_DWORD", $iValue) = 1 Then Return 1
        Else
            Return 0
        EndIf
    EndIf
    Return 0
EndFunc   ;==>_ServiceStartType

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

This is pretty basic so I'm not including examples just yet. Just #include the enclosed services.au3 file.

cool man!

i was trying to work with sysinternals.com's psservice.exe file to check on the service status.

now with this i can no longer require any 3rd party.

thanks for contributing!


New to script...But getting the hang of it.

Share this post


Link to post
Share on other sites

I was missing one little thing in all those posts about service managing so i wrote this little one. If you can/want add it to the service managing on first post or so.

MsgBox(0, "Test", _ServiceStartType("Carboncopy32", "Disabled"))

;===============================================================================
; Description:   Sets StartType of a service on a computer
; Author:        MadBoy
; Parameters:    $sComputerName - name of the target computer. If empty, the local computer name is used
;                 $sStatus - status of the service to set. Possible options are "Auto", "Manual", "Disabled".
;                $sServiceName - name of the service to set start type for
; Requirements:  None
; Return Values: On Success - 1
;                On Failure - 0
; Note:          This function does not stop/start service.
;===============================================================================
Func _ServiceStartType($sServiceName, $sStatus, $sComputerName = "")
    Local $iValue
    Local $sServiceKeyPath = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\" & $sServiceName

    If $sStatus = "Auto" Then $iValue = "2"
    If $sStatus = "Manual" Then $iValue = "3"
    If $sStatus = "Disabled" Then $iValue = "4"
    
    If $sComputerName = "" Then
        If RegRead($sServiceKeyPath, "Start") <> "" Then
            If RegWrite($sServiceKeyPath, "Start", "REG_DWORD", $iValue) = 1 Then Return 1
        Else
            Return 0
        EndIf
    Else
        If RegRead("\\" & $sComputerName & "\" & $sServiceKeyPath, "Start") <> "" Then
            If RegWrite("\\" & $sComputerName & "\" & $sServiceKeyPath, "Start", "REG_DWORD", $iValue) = 1 Then Return 1
        Else
            Return 0
        EndIf
    EndIf
    Return 0
EndFunc   ;==>_ServiceStartType
Nice one!

Added to my first post.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

@GEOSoft, nice UDF and to all the additions made.

Cheers! :whistle:

Share this post


Link to post
Share on other sites

@GEOSoft, nice UDF and to all the additions made.

Cheers! :whistle:

Thanks @busysignal. I'll be updating the download file soon.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thanks @busysignal. I'll be updating the download file soon.

VERY interesting.

This would be an occasion to completely rewrite my personnal batch files in .AU3 format :whistle:

If anyone is interested in seeing my service-related batchfiles, just reply to this, I'll be happy to oblige.

P.S.: Do you guys know it there's a sure-fire way to restore a deleted service? I've tried to restore the registry with a .REG file and it wasn't very satisfactory.


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

Hello.

I've added the function _ServicesGetDetails($Computer = "."), which returning a detailed list of all installed services.

The comment includes a little example.

;===============================================================================
; Description:     Returns a list of details of all currently defined Windows Services
; Syntax:          _ServicesGetDetails([$Computer])
; Parameter(s):    $Computer - The network name of the computer (optional) The local computer is default
; Requirement(s):  None
; Return Value(s): Success - Returns an array of the details of Services.
;                  A servicedetail is a string and has elements separated by "|", exam. "MyPC|svchost|..."
;                  Array[0]     contains the number N of Services
;                  Array[1..N]  contains the Strings of servicedetails
;                  Meaning:     (-1 = Yes, 0 = No)
;                  Pos. in string    [1] = Computer Network Name
;                                    [2] = Service Name
;                                    [3] = Service Type (Own Process, Share Process)
;                                    [4] = Service State (Stopped, Running, Paused)
;                                    [5] = Exit Code (0, 1077)
;                                    [6] = Process ID
;                                    [7] = Can Be Paused (-1, 0)
;                                    [8] = Can Be Stopped (-1, 0)
;                                    [9] = Caption
;                                    [10] = Description
;                                    [11] = Can Interact With Desktop (-1, 0)
;                                    [12] = Display Name
;                                    [13] = Error Control (Normal, Ignore)
;                                    [14] = Executable Path Name
;                                    [15] = Service Started (-1, 0)
;                                    [16] = Start Mode (Auto, Manual, Disabled)
;                                    [17] = Account Name (LocalSystem, NT AUTHORITY\LocalService, NT AUTHORITY\NetworkService)
;                  Failure Sets @Error = -1 if services not found
; Author(s)        GEOSoft, ReCoder
; Modification(s):
; Note(s):
; Example(s):
;~ #include <GuiConstants.au3>
;~ #include <GuiListView.au3>
;~ ;#include "services.au3"
;~
;~ Local $sDtl = "System Name|Name|Type|State|ExitCode|Process ID|Can Pause|Can Stop" & _
;~              "|Caption|Description|Interact With DskTop|Display Name" & _
;~              "|Error Control|Exec File Path|Started|Start Mode|Account"
;~ Local $aDtl = StringSplit($sDtl, '|')
;~ #region GUI definitions
;~ GuiCreate("MyGUI", 810, 487,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
;~ Dim $process_list_view = GUICtrlCreateListView( $sDtl, 10, 10, 790, 440, _
;~                                    $LVS_SHOWSELALWAYS, $LVS_EX_GRIDLINES )
;~ $btnRefresh = GuiCtrlCreateButton("Refresh", 20, 460, 150, 20)
;~ GetServicesInfos($process_list_view)
;~ GuiSetState()
;~
;~ While 1
;~  $msg = GuiGetMsg()
;~  Select
;~    Case $msg = $GUI_EVENT_CLOSE
;~      ExitLoop
;~      Case $msg = $btnRefresh
;~         GetServicesInfos($process_list_view)
;~    Case Else
;~      ;;;
;~  EndSelect
;~ WEnd
;~ Exit
;~
;~ Func GetServicesInfos(ByRef $ListView)
;~     Local $aServices = _ServicesGetDetails() ;# n Services, Array[1..n]
;~     Local $Top_Item = _GUICtrlListViewGetTopIndex($ListView)
;~     _GUICtrlListViewDeleteAllItems($ListView)
;~     For $i = 1 To $aServices[0]
;~         GUICtrlCreateListViewItem($aServices[$i], $Listview)
;~     Next
;~     _GUICtrlListViewEnsureVisible($ListView, $Top_Item, 1)
;~ EndFunc
;===============================================================================
Func _ServicesGetDetails($Computer = ".")
    Local $Rtn, $aRet[1] = [0]
    Local $Service = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
    Local $sItems = $Service.ExecQuery ("Select * from Win32_Service")
    For $objService In $sItems
        Local $i = UBound($aRet)
        ReDim $aRet[$i+1]
        $Rtn  = $objService.SystemName & '|' & $objService.Name & '|' & $objService.ServiceType & '|' & $objService.State & '|'
        $Rtn &= $objService.ExitCode & '|' & $objService.ProcessID & '|' & $objService.AcceptPause & '|' & $objService.AcceptStop & '|'
        $Rtn &= $objService.Caption & '|' & $objService.Description & '|' & $objService.DesktopInteract & '|' & $objService.DisplayName & '|'
        $Rtn &= $objService.ErrorControl & '|' & $objService.PathName & '|' & $objService.Started & '|' & $objService.StartMode & '|'
        $Rtn &= $objService.StartName
        $aRet[$i] = $Rtn    ;# Service[$i].Infos
        $aRet[0] = $i       ;# Anzahl Services
    Next
    Return $aRet
EndFunc   ;==>_ServicesGetDetailsoÝ÷ Øg{Hb~'~éܶ*'±ú+q©ex²)àꮢۮøz«¨¶X¤y'«¼g­JÖ­{MúÖ¦{Mú
©º×«oÝ÷ Ù«­¢+Øìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ìÍÉ¥ÁÑ¥½¸èIÑÕɸѡѥ±Ì½]¥¹½ÝÌMÉÙ¥(ìMå¹Ñàè}MÉÙÑÑ¥±Ì ÀÌØí¥9µl°ÀÌØí
½µÁÕÑÉt¤(ìAɵÑȡ̤èÀÌØí¥9µ´Q¡¹µ½Ñ¡ÍÉ٥Ѽ¡¬(ìÀÌØí
½µÁÕÑÈ´Q¡¹Ñݽɬ¹µ½Ñ¡½µÁÕÑÈ¡½ÁÑ¥½¹°¤Q¡±½°½µÁÕÑÈ¥ÌÕ±Ð(ìIÅեɵ¹Ð¡Ì¤è9½¹(ìIÑÕɸY±Õ¡Ì¤èMÕÍÌ´IÑÕɹ̸ÉÉä½Ñ¡ÍÉ٥ѥ±Ìݡɱµ¹Ð ´ÄôeÌ°Àô9¼¤(ìlÅtô
½µÁÕÑÈ9Ñݽɬ9µ(ìlÉtôMÉÙ¥9µ(ìlÍtôMÉÙ¥QåÁ¡=ݸAɽÍÌ°M¡ÉAɽÍ̤(ìlÑtôMÉÙ¥MÑÑ¡MѽÁÁ°IÕ¹¹¥¹°AÕͤ(ìlÕtôá¥Ð
½ À°ÄÀÜܤ(ìlÙtôAɽÍÌ%(ìlÝtô
¸  AÕÍ ´Ä°À¤(ìlátô
¸  MѽÁÁ ´Ä°À¤(ìlåtô
ÁÑ¥½¸(ìlÄÁtôÍÉ¥ÁÑ¥½¸(ìlÄÅtô
¸%¹ÑÉÐ]¥Ñ ͭѽÀ ´Ä°À¤(ìlÄÉtô¥ÍÁ±ä9µ(ìlÄÍtôÉɽÈ
½¹Ñɽ°¡9½Éµ°°%¹½É¤(ìlÄÑtôáÕѱAÑ 9µ(ìlÄÕtôMÉÙ¥MÑÉÑ ´Ä°À¤(ìlÄÙtôMÑÉÐ5½¡ÕѼ°5¹Õ°°¥Í±¤(ìlÄÝtô½Õ¹Ð9µ¡1½±MåÍÑ´°9PUQ!=I%QdÀäÈí1½±MÉÙ¥°9PUQ!=I%QdÀäÈí9ÑݽɭMÉÙ¥¤(쥱ÕÉMÑÌÉɽÈô´Ä¥ÍÉÙ¥¹½Ð½Õ¹(ìÕÑ¡½È¡Ì¤=M½Ð°I
½È(ì5½¥¥Ñ¥½¸¡Ì¤è(ì9½Ñ¡Ì¤è(ìáµÁ±¡Ì¤è(íø1½°ÀÌØíYÈô}MÉÙÑÑ¥±Ì ÀÌØíÍMÉÙ¥9µ¤(íø1½°ÀÌØíÍÑ°ôÅÕ½ÐíMåÍÑ´9µñ9µñQåÁñMÑÑñá¥Ñ
½ñAɽÍÌ%ñ
¸AÕÍñ
¸MѽÁñ
ÁÑ¥½¹ñÍÉ¥ÁÑ¥½¹ðÅÕ½ÐìµÀì|(íøÅÕ½Ðí%¹ÑÉÐ]¥Ñ Í­Q½Áñ¥ÍÁ±ä9µñÉɽÈ
½¹Ñɽ±ñᥱAÑ¡ñMÑÉÑñMÑÉÐ5½ñ½Õ¹ÐÅÕ½Ðì(íø1½°ÀÌØíÑ°ôMÑÉ¥¹MÁ±¥Ð ÀÌØíÍÑ°°ÌäíðÌäì¤(íø1½°ÀÌØíÍ5ÍÑáÐôMÑÉ¥¹½ÉµÐ ÅÕ½Ðì´ÌÁÌè´ÈÁÌÅÕ½ÐìµÀì
I1°ÅÕ½ÐíMÉÙ¥ÁɵÑÈÅÕ½Ðì°ÅÕ½ÐíY±ÕÅÕ½Ðì¤(íø½ÈÀÌØí¤ôÄQ¼ÀÌØíѱlÁtìM¡½Õ±ÅհѼÀÌØíYÉlÁt(íøÀÌØíÍ5ÍÑáÐôÀÌØíÍ5ÍÑáеÀìMÑÉ¥¹½ÉµÐ ÅÕ½Ðì´ÌÁÌè´ÈÁÌÅÕ½ÐìµÀì
I1°ÀÌØíѱlÀÌØí%t°ÀÌØíYÉlÀÌØí%t¤(íø9áÐ(íø5Í ½à ÐÀäØ°MÑÉ¥¹½ÉµÐ ÅÕ½ÐíMÉÙ¥èÌäìÌÌäìÅÕ½Ðì°ÀÌØíÍMÉÙ¥9µ¤°ÀÌØíÍ5ÍÑáаÈÀ¤(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô()Õ¹}MÉÙÑÑ¥±Ì ÀÌØí¥9µ°ÀÌØí
½µÁÕÑÈôÅÕ½Ðì¸ÅÕ½Ðì¤(1½°ÀÌØíIѸ(1½°ÀÌØíMÉÙ¥ô=©Ð ÅÕ½ÐíÝ¥¹µµÑÌèÀäÈìÀäÈìÅÕ½ÐìµÀìÀÌØí
½µÁÕÑȵÀìÅÕ½ÐìÀäÈíɽ½ÐÀäÈí¥µØÈÅÕ½Ðì¤(1½°ÀÌØíÍ%ѵÌôÀÌØíMÉÙ¥¹áEÕÉä ÅÕ½ÐíM±Ð¨É½´]¥¸ÌÉ}MÉ٥ݡɹµ±¥­ÌäìÅÕ½ÐìµÀìÀÌØí¥9µµÀìÅÕ½ÐìÌäìÅÕ½Ðì¤(½ÈÀÌØí½©MÉÙ¥%¸ÀÌØíÍ%ѵÌìQ­Ñ¡¥ÉÍн©Ðɽ´Ñ¡½±±Ñ¥½¸¹ÉÑÕɸ(ÀÌØíIѸôÀÌØí½©MÉÙ¥¹MåÍѵ9µµÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹9µµÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹MÉÙ¥QåÁµÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹MÑѵÀìÌäíðÌäì(ÀÌØíIѸµÀìôÀÌØí½©MÉÙ¥¹á¥Ñ
½µÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹AɽÍÍ%µÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹ÁÑAÕ͵ÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹ÁÑMѽÀµÀìÌäíðÌäì(ÀÌØíIѸµÀìôÀÌØí½©MÉÙ¥¹
ÁÑ¥½¸µÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹ÍÉ¥ÁÑ¥½¸µÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹Í­Ñ½Á%¹ÑÉеÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹¥ÍÁ±å9µµÀìÌäíðÌäì(ÀÌØíIѸµÀìôÀÌØí½©MÉÙ¥¹ÉɽÉ
½¹Ñɽ°µÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹AÑ¡9µµÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹MÑÉѵÀìÌäíðÌäìµÀìÀÌØí½©MÉÙ¥¹MÑÉÑ5½µÀìÌäíðÌäì(ÀÌØíIѸµÀìôÀÌØí½©MÉÙ¥¹MÑÉÑ9µ(IÑÕɸMÑÉ¥¹MÁ±¥Ð ÀÌØíIѸ°ÌäíðÌäì¤(9áÐ(IÑÕɸMÑÉÉ½È ´Ä¤)¹Õ¹ìôôÐí}MÉÙÑÑ¥±oÝ÷ Ù«­¢+Øìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ìÍÉ¥ÁÑ¥½¸èIÑÕɸѡÕÉɹÐÍÑѽ]¥¹½ÝÌMÉÙ¥(ìMå¹Ñàè}MÉÙÑMÑÑ ÀÌØí¥9µl°ÀÌØí
½µÁÕÑÉt¤(ìAɵÑȡ̤èÀÌØí¥9µ´Q¡¹µ½Ñ¡ÍÉ٥Ѽ¡¬(ìÀÌØí
½µÁÕÑÈ´Q¡¹Ñݽɬ¹µ½Ñ¡½µÁÕÑÈ¡½ÁÑ¥½¹°¤Q¡±½°½µÁÕÑÈ¥ÌÕ±Ð(ìIÅեɵ¹Ð¡Ì¤è9½¹(ìIÑÕɸY±Õ¡Ì¤èMÕÍÌ´IÑÕɹÌÑ¡ÍÑѽѡÍÉÙ¥(쥱ÕÉMÑÌÉɽÈô´Ä¥ÍÉÙ¥¹½Ð½Õ¹(ìÕÑ¡½È¡Ì¤=M½Ð°I
½È(ì5½¥¥Ñ¥½¸¡Ì¤è(ì9½Ñ¡Ì¤è(ìáµÁ±¡Ì¤è(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô()Õ¹}MÉÙÑMÑÑ ÀÌØí¥9µ°ÀÌØí
½µÁÕÑÈôÅÕ½Ðì¸ÅÕ½Ðì¤(1½°ÀÌØíMÉÙ¥ô=©Ð ÅÕ½ÐíÝ¥¹µµÑÌèÀäÈìÀäÈìÅÕ½ÐìµÀìÀÌØí
½µÁÕÑȵÀìÅÕ½ÐìÀäÈíɽ½ÐÀäÈí¥µØÈÅÕ½Ðì¤(1½°ÀÌØíÍ%ѵÌôÀÌØíMÉÙ¥¹áEÕÉä ÅÕ½ÐíM±Ð¨É½´]¥¸ÌÉ}MÉ٥ݡɹµ±¥­ÌäìÅÕ½ÐìµÀìÀÌØí¥9µµÀìÅÕ½ÐìÌäìÅÕ½Ðì¤(½ÈÀÌØí½©%Ñ´%¸ÀÌØíÍ%ѵÌ(IÑÕɸÀÌØí½©%Ñ´¹MÑÑ(9áÐ(IÑÕɸMÑÉÉ½È ´Ä¤)¹Õ¹ìôôÐí}MÉÙÑMÑÑoÝ÷ Ù«­¢+Øìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ìÍÉ¥ÁÑ¥½¸èAÕÍ]¥¹½ÝÌMÉÙ¥(ìMå¹Ñàè}MÉÙAÕÍ ÀÌØí¥9µl°ÀÌØí
½µÁÕÑÉt¤(ìAɵÑȡ̤èÀÌØí¥9µ´Q¡¹µ½Ñ¡ÍÉ٥ѼÍÑÉÐ(ìÀÌØí
½µÁÕÑÈ´Q¡¹Ñݽɬ¹µ½Ñ¡½µÁÕÑÈ¡½ÁÑ¥½¹°¤¸Q¡±½°½µÁÕÑÈ¥ÌÕ±Ð(ìIÅեɵ¹Ð¡Ì¤è9½¹(ìIÑÕɸY±Õ¡Ì¤èMÕÍÌ´AÕÍÌÑ¡ÍÉÙ¥(쥱ÕÉ´MÑÌÉɽÈô´Ä¥ÍÉÙ¥¹½Ð½Õ¹½ÈÍÉÙ¥¥Ì(ì±ÉäÁÕÍ(ìÕÑ¡½È¡Ì¤=M½Ð°I
½È(ì5½¥¥Ñ¥½¸¡Ì¤è(ì9½Ñ¡Ì¤è5åÑ¡M1
PÉÑÕɹ̵½ÉÑ¡¸ÄI½ÝÍа½¹±äÑ¡¥ÉÍÐ(ìI½ÝÍÐÝ¥±°Ñ­¸(ìáµÁ±¡Ì¤è(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô()Õ¹}MÉÙAÕÍ ÀÌØí¥9µ°ÀÌØí
½µÁÕÑÈôÅÕ½Ðì¸ÅÕ½Ðì¤(1½°ÀÌØíMÉÙ¥ô=©Ð ÅÕ½ÐíÝ¥¹µµÑÌèÀäÈìÀäÈìÅÕ½ÐìµÀìÀÌØí
½µÁÕÑȵÀìÅÕ½ÐìÀäÈíɽ½ÐÀäÈí¥µØÈÅÕ½Ðì¤(1½°ÀÌØíÍ%ѵÌôÀÌØíMÉÙ¥¹áEÕÉä ÅÕ½ÐíM±Ð¨É½´]¥¸ÌÉ}MÉÙ¥]¡ÉMÑÑôÌäíIÕ¹¹¥¹Ìäì¹¹µ±¥­ÌäìÅÕ½ÐìµÀìÀÌØí¥9µµÀìÅÕ½ÐìÌäìÅÕ½Ðì¤(½ÈÀÌØí½©MÉÙ¥%¸ÀÌØíÍ%ѵÌ(ÀÌØí½©MÉÙ¥¹AÕÍMÉÙ¥ ÀÌØí½©MÉÙ¥¹9µ¤(IÑÕɸ(9áÐ(IÑÕɸMÑÉÉ½È ´Ä¤)¹Õ¹ìôôÐí}MÉÙAÕÍoÝ÷ Ù«­¢+Øìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ìÍÉ¥ÁÑ¥½¸èIÍÕµÌÁÉÙ¥½ÕͱäÁÕÍ]¥¹½ÝÌÕѼµÍÑÉÐÍÉÙ¥(ìMå¹Ñàè}MÉÙIÍÕµ ÀÌØí¥9µl°ÀÌØí
½µÁÕÑÉt¤(ìAɵÑȡ̤èÀÌØí¥9µ´Q¡¹µ½Ñ¡ÍÉ٥ѼÍÑÉÐ(ìÀÌØí
½µÁÕÑÈ´Q¡¹Ñݽɬ¹µ½Ñ¡½µÁÕÑÈ¡½ÁÑ¥½¹°¤¸Q¡±½°½µÁÕÑÈ¥ÌÕ±Ð(ìIÅեɵ¹Ð¡Ì¤è9½¹(ìIÑÕɸY±Õ¡Ì¤èMÕÍÌ´IÍÕµÌÑ¡ÍÉÙ¥(쥱ÕÉMÑÌÉɽÈô´Ä¥ÍÉÙ¥¹½Ð½Õ¹(ìÕÑ¡½È¡Ì¤=M½Ð°I
½È(ì5½¥¥Ñ¥½¸¡Ì¤è(ì9½Ñ¡Ì¤è(ìáµÁ±¡Ì¤è(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô()Õ¹}MÉÙIÍÕµ ÀÌØí¥9µ°ÀÌØí
½µÁÕÑÈôÅÕ½Ðì¸ÅÕ½Ðì¤(1½°ÀÌØíMÉÙ¥ô=©Ð ÅÕ½ÐíÝ¥¹µµÑÌèÀäÈìÀäÈìÅÕ½ÐìµÀìÀÌØí
½µÁÕÑȵÀìÅÕ½ÐìÀäÈíɽ½ÐÀäÈí¥µØÈÅÕ½Ðì¤(1½°ÀÌØíÍ%ѵÌôÀÌØíMÉÙ¥¹áEÕÉä ÅÕ½ÐíM±Ð¨É½´]¥¸ÌÉ}MÉÙ¥]¡ÉMÑÑôÌäíAÕÍÌäì¹MÑÉÑ5½ôÌäíÕѼÌäì¹¹µ±¥­ÌäìÅÕ½ÐìµÀìÀÌØí¥9µµÀìÅÕ½ÐìÌäìÅÕ½Ðì¤(½ÈÀÌØí½©MÉÙ¥%¸ÀÌØíÍ%ѵÌ(ÀÌØí½©MÉÙ¥¹IÍÕµMÉÙ¥ ÀÌØí½©MÉÙ¥¹9µ¤(IÑÕɸ(9áÐ(IÑÕɸMÑÉÉ½È ´Ä¤)¹Õ¹ìôôÐí}MÉÙIÍÕµ

All modification based on the source of GEOSoft

Share this post


Link to post
Share on other sites

I have a little problem:

I tested _ServListInstalled on my rig so I can integrate it (with full credits!) to my Policy Lister.

The only thing i get is "".

Error is 0 so it looks like the function didn't hit any snag (more on this later).

WMi seems ok on my system, the service itself is up and running.

I'm running XP SP2 32 bits (in french)

Hopefully I'm just plain stupid but here goes anyways :whistle:

Here's a copy of the lines I wrote in my test program:

$Bingo1 =  _ServListInstalled(".")
$Bingo2 = @error
MsgBox(0,"services",$Bingo2&@CR&$Bingo1)
Exit

I also debugged $Service and $sItems but AutoIt never gets to the great consolewrite line in the sky, it just returns from the function empty handed. Hence the aformentionned error # is bogus. Something did happen. But no one's talking :lmao:

So am I right to assume my WMI needs a bit of man handling ;)

Which brings me to the following questions:

Is there an easy way (with AutoIT3) to detect if a computer has WMI installed?

Is there an easy way (with AutoIT3) to detect if WMI is working properly?

@WMI_Exists anyone :P

Also does it mean I would need some of this:

Only if there is no way to prevent a COM error, you could install an "Error Handler" in which you take action after the error has happened. It is not a solution to make a buggy script work properly. Neither does it catch non-COM related script errors (e.g. declaration and syntax errors).

... directly from the manual: COM Extensions to AutoIt

Finally your UDFs specify:

; Requirement(s): None

Should'nt this read "WMI capable operating system" ?

Picky picky picky :P

P.S.: I'll flush that WMI repository and restart my PC, and repost the results here.

P.P.S.: This script that also uses WMI works OK for me: http://www.autoitscript.com/forum/index.ph...8545&hl=wmi


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

Hi Celeri, check this out :whistle:

$Bingo1 =  _ServListInstalled()
$Bingo2 = @error
$srvlist=''
For $i = 1 To $Bingo1[0]
    $srvlist &= $Bingo1[$i] & '|'
Next
$srvlist = StringTrimRight($srvlist, 1)
MsgBox(0,"services",$Bingo2&@CR&$srvlist)
Exit

The function _ServListInstalled() returns an array !!

I modified your testscript to show the whole content of the array (i do the same like the function do --> build a string from single values)

I think this fix your problem.

Share this post


Link to post
Share on other sites

I don't see a function to create a service. Is this not possible or something?


My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Hi Celeri, check this out :whistle:

$Bingo1 =  _ServListInstalled()
$Bingo2 = @error
$srvlist=''
For $i = 1 To $Bingo1[0]
    $srvlist &= $Bingo1[$i] & '|'
Next
$srvlist = StringTrimRight($srvlist, 1)
MsgBox(0,"services",$Bingo2&@CR&$srvlist)
Exit

The function _ServListInstalled() returns an array !!

I modified your testscript to show the whole content of the array (i do the same like the function do --> build a string from single values)

I think this fix your problem.

Well I feel dumb but at least this works :lmao:

Thanks a million!

Edited by Celeri

I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

Thanks to all for this great thread. I have been looking for something to control services for a while now. This is great!

Share this post


Link to post
Share on other sites

I don't see a function to create a service. Is this not possible or something?

I know I haven't even looked at that possibility yet. Perhaps someone else has.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I'm having some problems using this UDF.

When i run it on the local machine there is no problem. But when I try on a remote machine I get the following error:

C:\PROGRA~1\AutoIt3\Include\Services.au3 (122) : ==> Variable must be of type "Object".:

$sItems = $Service.ExecQuery("Select * from Win32_Service")

$sItems = $Service^ ERROR

The code is:

#include <Services.au3>
$Bingo1 =  _ServListInstalled("\\machineid")
$Bingo2 = @error
$srvlist=''
For $i = 1 To $Bingo1[0]
    ConsoleWrite($bingo1[$i]&"|")
Next
Exit
Edited by RulleStenen

It´s Only Rock´n´Roll, But I Like It

Share this post


Link to post
Share on other sites

I'm having some problems using this UDF.

When i run it on the local machine there is no problem. But when I try on a remote machine I get the following error:

C:\PROGRA~1\AutoIt3\Include\Services.au3 (122) : ==> Variable must be of type "Object".:

$sItems = $Service.ExecQuery("Select * from Win32_Service")

$sItems = $Service^ ERROR

The code is:

#include <Services.au3>
$Bingo1 =  _ServListInstalled("\\machineid")
$Bingo2 = @error
$srvlist=''
For $i = 1 To $Bingo1[0]
    ConsoleWrite($bingo1[$i]&"|")
Next
Exit
What happens if you use _ServListInstalled("machineid") ?

I don't have a nework available right now to test it.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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