delphi 如何把自身写入系统服务自启动?注意是服务!! delphi 如何把自身写入系统服务自启动?注意是服务!(提...

delphi \u5982\u4f55\u628a\u81ea\u8eab\u5199\u5165\u7cfb\u7edf\u670d\u52a1\u81ea\u542f\u52a8\uff1f\u6ce8\u610f\u662f\u670d\u52a1\uff01

\u4e0d\u8981\u5199\u75c5\u6bd2\u3002\u3002\u3002

\u5199\u6ce8\u518c\u8868\u5230\u8fd9\u4e2a\u5206\u652f\uff0c\u5177\u4f53\u683c\u5f0f\u53c2\u7167\u5176\u5b83\u670d\u52a1
\u201cHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\u201d
\u5176\u5b9e\u670d\u52a1\u5c31\u662f\u4e00\u4e2a\u901a\u7528\u7a0b\u5e8f\uff0c\u4e3a\u7cfb\u7edf\u63d0\u4f9b\u67d0\u79cd\u529f\u80fd\u3002\u5b83\u548c\u5176\u5b83\u7a0b\u5e8f\u6ca1\u6709\u592a\u5927\u7684\u533a\u522b\uff0c\u53ea\u4e0d\u8fc7\u662f\u5728\u6dfb\u52a0\u5220\u9664\u7a0b\u5e8f\u4e2d\u627e\u4e0d\u5230\u3002
\u53e6\u5916\u4e0b\u8f7d\u8fd9\u4e2a\u8f6f\u4ef6\uff0c\u53ef\u4ee5\u5728\u7a0b\u5e8f\u4e2d\u8c03\u7528\u8be5\u8f6f\u4ef6\uff0c\u7ed9\u51fa\u5e94\u7528\u7a0b\u5e8f\u540d\u548c\u5b58\u50a8\u8def\u5f84\u5373\u53ef\u3002
http://www.basta.com/Software/SetupAppToService.exe
\u4e0a\u9762\u7684\u5730\u5740\u4e0d\u884c\u7684\u8bdd\u7528\u8fd9\u4e2a
http://jlbc.skycn.com/down/SetupAppToService.zip

Delphi服务程序注册与卸载

uses winsvc;
function InstallService(ServiceName, DisplayName, FileName: string): boolean;
var
SCManager,Service: THandle;
Args: pchar;
begin
Result := False;
SCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if SCManager = 0 then Exit;
try
Service := CreateService(SCManager, //句柄
PChar(ServiceName), //服务名称
PChar(DisplayName), //显示服务名
SERVICE_ALL_ACCESS, //服务访问类型
SERVICE_WIN32_OWN_PROCESS, //服务类型 or SERVICE_INTERACTIVE_PROCESS
SERVICE_AUTO_START, //自动启动服务
SERVICE_ERROR_IGNORE, //忽略错误
PChar(FileName), //启动的文件名
nil, //name of load ordering group (载入组名) 'LocalSystem'
nil, //标签标识符
nil, //相关性数组名
nil, //帐户(当前)
nil); //密码(当前)

Args := nil;
StartService(Service, 0, Args);
CloseServiceHandle(Service);
finally
CloseServiceHandle(SCManager);
end;
Result := True;
end;

procedure UninstallService(ServiceName: string);
var
SCManager,Service: THandle;
ServiceStatus: SERVICE_STATUS;
begin
SCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if SCManager = 0 then Exit;
try
Service := OpenService(SCManager, PChar(ServiceName), SERVICE_ALL_ACCESS);
ControlService(Service, SERVICE_CONTROL_STOP, ServiceStatus);
DeleteService(Service);
CloseServiceHandle(Service);
finally
CloseServiceHandle(SCManager);
end;
end;

procedure ServiceCtrlHandler(Control: dword); stdcall;
begin
case Control of
SERVICE_CONTROL_STOP:
begin
Stopped := True;
Status.dwCurrentState := SERVICE_STOPPED;
end;
SERVICE_CONTROL_PAUSE:
begin
Paused := True;
Status.dwcurrentstate := SERVICE_PAUSED;
end;
SERVICE_CONTROL_CONTINUE:
begin
Paused := False;
Status.dwCurrentState := SERVICE_RUNNING;
end;
SERVICE_CONTROL_INTERROGATE: ;
SERVICE_CONTROL_SHUTDOWN: Stopped := True;
end;
SetServiceStatus(StatusHandle, Status);
end;

扩展阅读:支配者dominatorapp下载 ... delphi变成什么了 ... delphi上位机开发 ... dll修复工具免费 ... delphi为什么被替代 ... delphi语言被淘汰了吗 ... 免费的dll修复软件 ... 表格怎么去除#div0 ... foxpro现在还有人用 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网