Jump to content

Enumerate Windows Services


Recommended Posts

Quick question (I hope): is it possible to get a list of the services on a computer?

And if it is, can you start/stop them etc?

Tnx in advance

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

Ok nice, could you tell me what key that would be for Win XP? Hope you can!

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

Tnx again Manadar :D

Though if someone knows how to control the services, I'm still listening!

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

Quick question (I hope): is it possible to get a list of the services on a computer?

And if it is, can you start/stop them etc?

Tnx in advance

1st part of question

$a_services = _RetrieveServices(@ComputerName)
If Not @error And IsArray($a_services) Then
    For $x = 1 To $a_services[0]
        MsgBox(0, "Service", $a_services[$x])
    Next
EndIf

Func _RetrieveServices($s_Machine)
    Local Const $wbemFlagReturnImmediately = 0x10
    Local Const $wbemFlagForwardOnly = 0x20
    Local $colItems = "", $even = 1, $objItem, $services
    Local $objWMIService = ObjGet("winmgmts:\\" & $s_Machine & "\root\CIMV2")
    If @error Then
        MsgBox(16, "_RetrieveServices", "ObjGet Error: winmgmts")
        Return
    EndIf
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If @error Then
        MsgBox(16, "_RetrieveServices", "ExecQuery Error: SELECT * FROM Win32_Service")
        Return
    EndIf
    If IsObj($colItems) Then
        For $objItem In $colItems
            If IsArray($services) Then
                ReDim $services[UBound($services) + 1]
            Else
                Dim $services[2]
            EndIf
            $services[0] = UBound($services) - 1
            $services[UBound($services) - 1] = $objItem.Name
        Next
        Return $services
    EndIf
EndFunc   ;==>_RetrieveServices
oÝ÷ ÛiÝ¥ªí¡ú®zËb¢v®¶­s`¢b33c·6W'f6RÒgV÷Cµ7ÖçFV2çFf'W2gV÷C°¤6öç6öÆUw&FRõ6WE6W'f6U7FFR6ö×WFW$æÖRÂb33c·6W'f6RÂgV÷Cµ7F÷gV÷C²fײÄb¥6ÆVWS¤6öç6öÆUw&FRõ6WE6W'f6U7FFR6ö×WFW$æÖRÂb33c·6W'f6RÂgV÷Cµ7F'BgV÷C²fײÄb ¤gVæ2õ6WE6W'f6U7FFRb33c·5÷2Âb33c·6W'f6RÂb33cµ7FFR Æö6Â6öç7Bb33c·v&VÔfÆu&WGW&äÖÖVFFVÇÒ Æö6Â6öç7Bb33c·v&VÔfÆtf÷'v&DöæÇÒ#  Æö6Âb33c¶6öÄFV×2ÒgV÷C²gV÷C²Âb33c¶ö&¤FVÒÂb33c·&WE÷7FGW2ÒÓ Æö6Âb33c¶÷7FGW5³#UÒÕ²gV÷Cµ7V66W72gV÷C²ÂgV÷C´æ÷B7W÷'FVBgV÷C²ÂgV÷C´66W72FVæVBgV÷C²ÂgV÷C´FWVæFVçB6W'f6W2'VææærgV÷C²Âð gV÷C´çfÆB6W'f6R6öçG&öÂgV÷C²ÂgV÷Cµ6W'f6R6ææ÷B66WB6öçG&öÂgV÷C²ÂgV÷Cµ6W'f6Ræ÷B7FfRgV÷C²ÂgV÷Cµ6W'f6R&WVW7BFÖV÷WBgV÷C²Âð gV÷CµVæ¶æ÷vâfÇW&RgV÷C²ÂgV÷CµFæ÷Bf÷VæBgV÷C²ÂgV÷Cµ6W'f6RÇ&VG7F÷VBgV÷C²ÂgV÷Cµ6W'f6RFF&6RÆö6¶VBgV÷C²ÂgV÷Cµ6W'f6RFWVæFVæ7FVÆWFVBgV÷C²Âð gV÷Cµ6W'f6RFWVæFVæ7fÇW&RgV÷C²ÂgV÷Cµ6W'f6RF6&ÆVBgV÷C²ÂgV÷Cµ6W'f6RÆövöâfÆVBgV÷C²ÂgV÷Cµ6W'f6RÖ&¶VBf÷"FVÆWFöâgV÷C²ÂgV÷Cµ6W'f6RæòF&VBgV÷C²Âð gV÷Cµ7FGW26&7VÆ"FWVæFVæ7gV÷C²ÂgV÷Cµ7FGW2GWÆ6FRæÖRgV÷C²ÂgV÷Cµ7FGW2ÒçfÆBæÖRgV÷C²ÂgV÷Cµ7FGW2ÒçfÆB&ÖWFW"gV÷C²Âð gV÷Cµ7FGW2ÒçfÆB6W'f6R66÷VçBgV÷C²ÂgV÷Cµ7FGW2Ò6W'f6RW7G2gV÷C²ÂgV÷Cµ6W'f6RÇ&VGW6VBgV÷CµÐ bærb33c·5÷2FVà Æö6Âb33c¶ö&¥tÔ6W'f6RÒö&¤vWBgV÷C·væÖv×G3¢b3#²b3#²gV÷C²fײb33c·5÷2fײgV÷C²b3#·&ö÷Bb3#´4Õc"gV÷C² bW'&÷"FVà ×6t&÷bÂgV÷Cµõ6WE6W'f6U7FFRgV÷C²ÂgV÷C´ö&¤vWBW'&÷#¢væÖv×G2gV÷C² &WGW&à VæD` b33c¶6öÄFV×2Òb33c¶ö&¥tÔ6W'f6RäWV5VW'gV÷Cµ4TÄT5B¢e$ôÒvã3%õ6W'f6RgV÷C²ÂgV÷CµuÂgV÷C²Âð b33c·v&VÔfÆu&WGW&äÖÖVFFVDzb33c·v&VÔfÆtf÷'v&DöæÇ bW'&÷"FVà ×6t&÷bÂgV÷Cµõ6WE6W'f6U7FFRgV÷C²ÂgV÷C´WV5VW'W'&÷#¢4TÄT5B¢e$ôÒvã3%õ6W'f6RgV÷C² &WGW&à VæD` b4ö&¢b33c¶6öÄFV×2FVà f÷"b33c¶ö&¤FVÒâb33c¶6öÄFV×0 bb33c¶ö&¤FVÒäæÖRÒb33c·6W'f6RFVà 6VÆV7@ 66Rb33cµ7FFRÒgV÷C´&ö÷BgV÷C²÷"b33cµ7FFRÒgV÷Cµ77FVÒgV÷C²÷"b33cµ7FFRÒgV÷C´WFöÖF2gV÷C²÷"b33cµ7FFRÒgV÷C´ÖçVÂgV÷C²÷"b33cµ7FFRÒgV÷C´F6&ÆVBgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒä6ævU7F'DÖöFRb33cµ7FFR 66Rb33cµ7FFRÒgV÷Cµ7F÷gV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒå7F÷6W'f6R 66Rb33cµ7FFRÒgV÷Cµ7F'BgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒå7F'E6W'f6R 66Rb33cµ7FFRÒgV÷CµW6RgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒåW6U6W'f6R 66Rb33cµ7FFRÒgV÷Cµ&W7VÖRgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒå&W7VÖU6W'f6R 66Rb33cµ7FFRÒgV÷C´FVÆWFRgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒäFVÆWFR VæE6VÆV7@ WDÆö÷ VæD` æW@ VæD` VæD` bb33c·&WE÷7FGW2fÇC²fwC²ÒFVà &WGW&âb33c¶÷7FGW5²b33c·&WE÷7FGW5Ð VÇ6P 6WDW'&÷" &WGW&âb33c·&WE÷7FGW0 VæD`¤VæDgVæ2³ÓÒfwCµõ6WE6W'f6U7FFP

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

1st part of question

$a_services = _RetrieveServices(@ComputerName)
If Not @error And IsArray($a_services) Then
    For $x = 1 To $a_services[0]
        MsgBox(0, "Service", $a_services[$x])
    Next
EndIf

Func _RetrieveServices($s_Machine)
    Local Const $wbemFlagReturnImmediately = 0x10
    Local Const $wbemFlagForwardOnly = 0x20
    Local $colItems = "", $even = 1, $objItem, $services
    Local $objWMIService = ObjGet("winmgmts:\\" & $s_Machine & "\root\CIMV2")
    If @error Then
        MsgBox(16, "_RetrieveServices", "ObjGet Error: winmgmts")
        Return
    EndIf
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If @error Then
        MsgBox(16, "_RetrieveServices", "ExecQuery Error: SELECT * FROM Win32_Service")
        Return
    EndIf
    If IsObj($colItems) Then
        For $objItem In $colItems
            If IsArray($services) Then
                ReDim $services[UBound($services) + 1]
            Else
                Dim $services[2]
            EndIf
            $services[0] = UBound($services) - 1
            $services[UBound($services) - 1] = $objItem.Name
        Next
        Return $services
    EndIf
EndFunc   ;==>_RetrieveServices
oÝ÷ ÛiÝ¥ªí¡ú®zËb¢v®¶­s`¢b33c·6W'f6RÒgV÷Cµ7ÖçFV2çFf'W2gV÷C°¤6öç6öÆUw&FRõ6WE6W'f6U7FFR6ö×WFW$æÖRÂb33c·6W'f6RÂgV÷Cµ7F÷gV÷C²fײÄb¥6ÆVWS¤6öç6öÆUw&FRõ6WE6W'f6U7FFR6ö×WFW$æÖRÂb33c·6W'f6RÂgV÷Cµ7F'BgV÷C²fײÄb ¤gVæ2õ6WE6W'f6U7FFRb33c·5÷2Âb33c·6W'f6RÂb33cµ7FFR Æö6Â6öç7Bb33c·v&VÔfÆu&WGW&äÖÖVFFVÇÒ Æö6Â6öç7Bb33c·v&VÔfÆtf÷'v&DöæÇÒ#  Æö6Âb33c¶6öÄFV×2ÒgV÷C²gV÷C²Âb33c¶ö&¤FVÒÂb33c·&WE÷7FGW2ÒÓ Æö6Âb33c¶÷7FGW5³#UÒÕ²gV÷Cµ7V66W72gV÷C²ÂgV÷C´æ÷B7W÷'FVBgV÷C²ÂgV÷C´66W72FVæVBgV÷C²ÂgV÷C´FWVæFVçB6W'f6W2'VææærgV÷C²Âð gV÷C´çfÆB6W'f6R6öçG&öÂgV÷C²ÂgV÷Cµ6W'f6R6ææ÷B66WB6öçG&öÂgV÷C²ÂgV÷Cµ6W'f6Ræ÷B7FfRgV÷C²ÂgV÷Cµ6W'f6R&WVW7BFÖV÷WBgV÷C²Âð gV÷CµVæ¶æ÷vâfÇW&RgV÷C²ÂgV÷CµFæ÷Bf÷VæBgV÷C²ÂgV÷Cµ6W'f6RÇ&VG7F÷VBgV÷C²ÂgV÷Cµ6W'f6RFF&6RÆö6¶VBgV÷C²ÂgV÷Cµ6W'f6RFWVæFVæ7FVÆWFVBgV÷C²Âð gV÷Cµ6W'f6RFWVæFVæ7fÇW&RgV÷C²ÂgV÷Cµ6W'f6RF6&ÆVBgV÷C²ÂgV÷Cµ6W'f6RÆövöâfÆVBgV÷C²ÂgV÷Cµ6W'f6RÖ&¶VBf÷"FVÆWFöâgV÷C²ÂgV÷Cµ6W'f6RæòF&VBgV÷C²Âð gV÷Cµ7FGW26&7VÆ"FWVæFVæ7gV÷C²ÂgV÷Cµ7FGW2GWÆ6FRæÖRgV÷C²ÂgV÷Cµ7FGW2ÒçfÆBæÖRgV÷C²ÂgV÷Cµ7FGW2ÒçfÆB&ÖWFW"gV÷C²Âð gV÷Cµ7FGW2ÒçfÆB6W'f6R66÷VçBgV÷C²ÂgV÷Cµ7FGW2Ò6W'f6RW7G2gV÷C²ÂgV÷Cµ6W'f6RÇ&VGW6VBgV÷CµÐ bærb33c·5÷2FVà Æö6Âb33c¶ö&¥tÔ6W'f6RÒö&¤vWBgV÷C·væÖv×G3¢b3#²b3#²gV÷C²fײb33c·5÷2fײgV÷C²b3#·&ö÷Bb3#´4Õc"gV÷C² bW'&÷"FVà ×6t&÷bÂgV÷Cµõ6WE6W'f6U7FFRgV÷C²ÂgV÷C´ö&¤vWBW'&÷#¢væÖv×G2gV÷C² &WGW&à VæD` b33c¶6öÄFV×2Òb33c¶ö&¥tÔ6W'f6RäWV5VW'gV÷Cµ4TÄT5B¢e$ôÒvã3%õ6W'f6RgV÷C²ÂgV÷CµuÂgV÷C²Âð b33c·v&VÔfÆu&WGW&äÖÖVFFVDzb33c·v&VÔfÆtf÷'v&DöæÇ bW'&÷"FVà ×6t&÷bÂgV÷Cµõ6WE6W'f6U7FFRgV÷C²ÂgV÷C´WV5VW'W'&÷#¢4TÄT5B¢e$ôÒvã3%õ6W'f6RgV÷C² &WGW&à VæD` b4ö&¢b33c¶6öÄFV×2FVà f÷"b33c¶ö&¤FVÒâb33c¶6öÄFV×0 bb33c¶ö&¤FVÒäæÖRÒb33c·6W'f6RFVà 6VÆV7@ 66Rb33cµ7FFRÒgV÷C´&ö÷BgV÷C²÷"b33cµ7FFRÒgV÷Cµ77FVÒgV÷C²÷"b33cµ7FFRÒgV÷C´WFöÖF2gV÷C²÷"b33cµ7FFRÒgV÷C´ÖçVÂgV÷C²÷"b33cµ7FFRÒgV÷C´F6&ÆVBgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒä6ævU7F'DÖöFRb33cµ7FFR 66Rb33cµ7FFRÒgV÷Cµ7F÷gV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒå7F÷6W'f6R 66Rb33cµ7FFRÒgV÷Cµ7F'BgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒå7F'E6W'f6R 66Rb33cµ7FFRÒgV÷CµW6RgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒåW6U6W'f6R 66Rb33cµ7FFRÒgV÷Cµ&W7VÖRgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒå&W7VÖU6W'f6R 66Rb33cµ7FFRÒgV÷C´FVÆWFRgV÷C° b33c·&WE÷7FGW2Òb33c¶ö&¤FVÒäFVÆWFR VæE6VÆV7@ WDÆö÷ VæD` æW@ VæD` VæD` bb33c·&WE÷7FGW2fÇC²fwC²ÒFVà &WGW&âb33c¶÷7FGW5²b33c·&WE÷7FGW5Ð VÇ6P 6WDW'&÷" &WGW&âb33c·&WE÷7FGW0 VæD`¤VæDgVæ2³ÓÒfwCµõ6WE6W'f6U7FFP
nice
Link to comment
Share on other sites

Wow keep getting surprised every time you pull a trick like that gary!

Tnx big time!

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

Absolutely final question: could gafrost's script be adapted so _RetrieveServices returns the current state of the service as well (I don't actually comprehend the script so I won't mess with it)? Tnx!

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

change:

$services[UBound($services) - 1] = $objItem.Name
oÝ÷ Ù:ºÚ"µÍÌÍÜÙXÙÖÕPÝ[
    ÌÍÜÙXÙÊHHWHH  ÌÍÛØ][K[YH  [È ][Ýß  ][ÝÈ  [È ÌÍÛØ][KÝ]B

you can then split the array item to seperate the name from the state

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

change:

$services[UBound($services) - 1] = $objItem.Name
oÝ÷ Ù:ºÚ"µÍÌÍÜÙXÙÖÕPÝ[
    ÌÍÜÙXÙÊHHWHH  ÌÍÛØ][K[YH  [È ][Ýß  ][ÝÈ  [È ÌÍÛØ][KÝ]B

you can then split the array item to seperate the name from the state

Well, again, tnx alot!

Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link to comment
Share on other sites

Hello Gafrost.

I'm very interested by the 2 scripts you launch in this topic !

I tried them but the interpreter return an error :-(

C:\Documents and Settings\OTO\Bureau\test.au3 (17) : ==> Unable to parse line.:

$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

$colItems = $objWMIService.E^ ERROR

I think that I have to specify "includes" in the script ?! But which one ?

Thanks a lot....

Link to comment
Share on other sites

Hello Gafrost.

I'm very interested by the 2 scripts you launch in this topic !

I tried them but the interpreter return an error :-(

C:\Documents and Settings\OTO\Bureau\test.au3 (17) : ==> Unable to parse line.:

$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

$colItems = $objWMIService.E^ ERROR

I think that I have to specify "includes" in the script ?! But which one ?

Thanks a lot....

Do you have beta?

Nomad :D

Link to comment
Share on other sites

Do you have beta?

Nomad :D

NO ! I have the 3.1.1.0 !!!!

It should work without "includes" ???

Some intructions like :

ObjGet

$objWMIService.ExecQuery

....

are not in the help file. So I thought they were AutoIt extensions ?!.....

Sorry for these noob questions..... :">

Link to comment
Share on other sites

NO ! I have the 3.1.1.0 !!!!

It should work without "includes" ???

Some intructions like :

ObjGet

$objWMIService.ExecQuery

....

are not in the help file. So I thought they were AutoIt extensions ?!.....

Sorry for these noob questions..... '>

I haven't tried it, but ObjGet, ObjCreate, etc.. are functions for beta only. Your OS will also be a factor as this might not work for windows 98, for example.

Link to comment
Share on other sites

I haven't tried it, but ObjGet, ObjCreate, etc.. are functions for beta only. Your OS will also be a factor as this might not work for windows 98, for example.

OK, thanks a lot, I'm going to get the beta version. The OS is not a problem for me : I only use NT-based Windows (2000, XP, 2003).

Thanks again.

Link to comment
Share on other sites

OK, thanks a lot, I'm going to get the beta version. The OS is not a problem for me : I only use NT-based Windows (2000, XP, 2003).

Thanks again.

No problem. If you have any problems after getting the beta, try re-installing SciTe, that fixed all my problems. Just a heads up. :D

Nomad :D

Link to comment
Share on other sites

Hello,

I'm trying to understand the Gafrost's script.... But I can't :-(

The only thing I want to do is : for a given service, knowing it state (start or stop).

I'd like to write a function such _GetServiceState (ServiceName) where "ServiceName" is a string giving the name of the service and where the function return the state (integer or string).

I think there is someting to do with this

$objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

but I don't know if I can add something to the SQL statement (something like : where Service_Name = Var_ServiceName).....

Thank you for your help....

Link to comment
Share on other sites

Maybe this can help you (suggestion of Gafrost using stringsplit)

$sServiceToCheck = "ALG"
MsgBox(0, $sServiceToCheck, _GetServiceState($sServiceToCheck))


Func _GetServiceState($sServiceName)
    $a_services = _RetrieveServices(@ComputerName)
    If Not @error And IsArray($a_services) Then
        For $x = 1 To $a_services[0]
            $aTemp = StringSplit($a_services[$x], "|")
            If $aTemp[1] = $sServiceName Then
                Return $aTemp[2]
            EndIf
        Next
        Return "Service not found"
    EndIf
EndFunc   ;==>_GetServiceState 

Func _RetrieveServices($s_Machine)
    Local Const $wbemFlagReturnImmediately = 0x10
    Local Const $wbemFlagForwardOnly = 0x20
    Local $colItems = "", $even = 1, $objItem, $services
    Local $objWMIService = ObjGet("winmgmts:\\" & $s_Machine & "\root\CIMV2")
    If @error Then
        MsgBox(16, "_RetrieveServices", "ObjGet Error: winmgmts")
        Return
    EndIf
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If @error Then
        MsgBox(16, "_RetrieveServices", "ExecQuery Error: SELECT * FROM Win32_Service")
        Return
    EndIf
    If IsObj($colItems) Then
        For $objItem In $colItems
            If IsArray($services) Then
                ReDim $services[UBound($services) + 1]
            Else
                Dim $services[2]
            EndIf
            $services[0] = UBound($services) - 1
;~             $services[UBound($services) - 1] = $objItem.Name
            $services[UBound($services) - 1] = $objItem.Name & "|" & $objItem.State
        Next
        Return $services
    EndIf
EndFunc   ;==>_RetrieveServices
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...