How can I enumerate all windows services and disable some of them?

Discussion in 'Python' started by could.net, Aug 22, 2006.

  1. could.net

    could.net Guest

    I know that Module win32service has some functions on manipulating
    win32 services.
    But I still have 2 questions:
    1. how to enumerate all services?
    2. how to disable a certain one?

    Thanks in advance!
     
    could.net, Aug 22, 2006
    #1
    1. Advertisements

  2. could.net

    Roger Upole Guest

    win32service.EnumServicesStatus lists services, and ChangeServiceConfig
    lets you change the start type to disabled.

    import win32service
    hscm=win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
    svcs=win32service.EnumServicesStatus(hscm)
    for svc in svcs:
    if svc[0]=='PyPipeTestService':
    hsvc=win32service.OpenService(hscm, svc[0], win32service.SERVICE_CHANGE_CONFIG)
    win32service.ChangeServiceConfig(hsvc, win32service.SERVICE_NO_CHANGE,
    win32service.SERVICE_DISABLED, win32service.SERVICE_NO_CHANGE, None, None,0,
    None,None,None,None)
    win32service.CloseServiceHandle(hsvc)
    win32service.CloseServiceHandle(hscm)


    Roger
     
    Roger Upole, Aug 22, 2006
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.