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

C

could.net

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!
 
R

Roger Upole

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!

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top