Rob*_*edy 19
打开的服务OpenService
,然后通过将禁用它Service_Disabled
作为dwStartType
为参数ChangeServiceConfig
.指定空指针或Service_No_Change
其余参数,因为您不想更改它们.
您可以使用JEDI组件库(JCL)中的文件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;
Run Code Online (Sandbox Code Playgroud)
除了使用以前的方法,如果您需要更多控制,您可以使用WMI.
使用Win32_Service类可以访问机器上安装的所有服务信息,您可以访问方法:启动,停止,暂停,恢复,查询,创建,删除,更改,更改创建模式...
在这里(Web/SourceForge),您可以找到一组与WMI 一起使用的组件(GLibWMI组件库); 有一个名为CServiceInfo thah为您提供此类的所有信息和一些方法.
除了包装tere是一些演示; 一个叫做(ServiceControl)并实现所有方法.
替代文字http://img341.imageshack.us/img341/8505/imagen336.png
所有包都包含来源.查看它对您有用的代码.
问候.
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);
Run Code Online (Sandbox Code Playgroud)