我使用了一个可以通过Delphi启动和停止服务的例程,但我还需要能够禁用它们,这是可能的吗?
发布于 2010-03-09 00:19:28
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);
发布于 2010-03-09 02:54:09
使用OpenService
打开服务,然后通过将Service_Disabled
作为ChangeServiceConfig
的dwStartType
参数传递来禁用它。为其余的参数指定一个空指针或Service_No_Change
,因为您对更改它们不感兴趣。
发布于 2010-03-11 23:50:38
你可以使用JEDI组件库中的JclSvcCtrl.pas文件。我已经写了一个你可以使用的伪例。但是,请注意我并没有对其进行测试。但在这种情况下,它应该工作(省略了错误检查):
M := TJclSCManager.Create;
M.Refresh(true); //Not sure if true is needed or not (refresh all services)
For i := 0 to M.ServiceCount -1 do
begin
S := M.Services[i]; //TJclNtService
if CompareText(S.ServiceName, 'bla') then
begin
S.Stop;
S.StartType := sstDisabled;
S.Commit;
break;
end;
end;
https://stackoverflow.com/questions/2401528
复制相似问题