Search code examples
delphiservice

How can I disable a service via Delphi?


I use a routine that can start and stop services via Delphi but I also need to be able to disable them, is it possible?


Solution

  • ShellExecute(0, nil, 'cmd.exe', 'sc config "the service name" start=disabled', nil, SW_HIDE);
    ShellExecute(0, nil, 'cmd.exe', 'sc config "the service name" start=auto', nil, SW_HIDE);
    ShellExecute(0, nil, 'cmd.exe', 'sc config "the service name" start=demand', nil, SW_HIDE);