How to remove a service or change the startup type to disabled

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Rapoport

    How to remove a service or change the startup type to disabled

    I'd like to programmaticall y remove a service or change its startup
    type to disabled. I know how to remove it from the command line but
    is there another way using the win32 extensions?

    I've looked through the win32 help file but when it lists the
    arguments for its methods (such as win32service.Ch angeServiceConf ig)
    it doesn't give a dictionary of possible arguments. How can I tell
    what int is associated with what Access Type (in OpenService), for
    example.

    Any help would be appreciated.

    Thanks,

    Matt
  • Tim Golden

    #2
    Re: How to remove a service or change the startup type to disabled

    matthew.rapopor t@accenture.com (Matt Rapoport) wrote in message news:<4150f6c8. 0308291044.2fb2 6d32@posting.go ogle.com>...[color=blue]
    > I'd like to programmaticall y remove a service or change its startup
    > type to disabled. I know how to remove it from the command line but
    > is there another way using the win32 extensions?[/color]

    Three answers:

    1) The win32service module has a load of constants
    for this sort of purpose. Do dir (win32service)
    and look for things in capitals. At the moment,
    I'll leave anyone else on the list who's had experience
    of this to answer specifics.

    2) Look at:



    3) Use wmi. Get the wmi module from



    and then do something like this:

    <code>

    import wmi

    c = wmi.WMI () # or c = wmi.WMI ("other_compute r")
    for service in c.Win32_Service (Name="unuseful _service"):
    service.ChangeS tartMode (StartMode="Aut omatic")
    for service in c.Win32_Service (Name="unwanted _service"):
    service.Delete ()

    </code>

    The loops are just a fudge for the fact the the wmi
    query always returns a list, albeit of length one. You
    could equally well do:

    service = c.Win32_Service (Name="unuseful _service")[0]

    although this has the disadvantage (or, possibly, advantage)
    of raising an exception if there is no such service.

    TJG

    Comment

    Working...