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

Discussion in 'Python' started by Matt Rapoport, Aug 29, 2003.

  1. I'd like to programmatically 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.ChangeServiceConfig)
    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
     
    Matt Rapoport, Aug 29, 2003
    #1
    1. Advertising

  2. Matt Rapoport

    Tim Golden Guest

    (Matt Rapoport) wrote in message news:<>...
    > I'd like to programmatically 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?


    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:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/115875

    3) Use wmi. Get the wmi module from

    http://tgolden.sc.sabren.com/python/wmi.html

    and then do something like this:

    <code>

    import wmi

    c = wmi.WMI () # or c = wmi.WMI ("other_computer")
    for service in c.Win32_Service (Name="unuseful_service"):
    service.ChangeStartMode (StartMode="Automatic")
    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
     
    Tim Golden, Sep 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Affan
    Replies:
    0
    Views:
    452
    Affan
    Jun 24, 2004
  2. sk
    Replies:
    1
    Views:
    377
  3. Askari
    Replies:
    2
    Views:
    725
    Askari
    Aug 30, 2004
  4. Dmitry Nogin

    CollectionEditor - Add/Remove buttons are disabled

    Dmitry Nogin, Apr 27, 2007, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    780
    ClayB
    Apr 28, 2007
  5. Replies:
    2
    Views:
    1,144
Loading...

Share This Page