怎么把某文件写入服务启动? 如题,要是我要把C:\1.EXE写入服务启动,那么要改要这么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; 刚喝了酒的(还是白酒),头晕,如果有不对的地方还请多包涵 写服务要建立服务工程,如果你的EXE不是服务,那么写入服务也无法“自动启动”。其实并不难,只是具体步骤有些烦琐。我以前写过,需要的话可以把这个工程发给你。 求一个delphi实现增删改查和数据录入功能的小程序 共享一套ERP源码,开发语言delphi5, 有兴趣的加QQ670582483。 请教一个简单问题,关于控件的创建,但是偶没搞明白 我的天,ACCESS做ADP功能太差了!! 难题,请各位大侠不吝惕教,(关于分组和group by) 急求大写人民币程序(关于发票程序) 那儿有详细的SQL命令的介绍? 看一下 谁能简要介绍一下stringgrid的用法? 如何把用ado的程序从sqlserver移植到db2? 这个效果可否有什么控件实现 SQL语句出现了'数据提供程序或其他服务返回e_fail状态 '怎么回事'?
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;
刚喝了酒的(还是白酒),头晕,如果有不对的地方还请多包涵
其实并不难,只是具体步骤有些烦琐。我以前写过,需要的话可以把这个工程发给你。