大佬教程收集整理的这篇文章主要介绍了Inno安装 – 在文件复制前正确停止服务,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
[Files] source: "Myservice.exe"; DestDir: "{app}"; check: IsServer; BeforeInstall: BeforeserviceInstall('Myservicename','Myservice.exe'); AfterInstall: AfterserviceInstall('Myservicename','Myservice.exe') procedure BeforeserviceInstall(SvcName,Filename: String); var S: Longword; begin //If service is installed,it needs to be stopped if serviceExists(SvcName) then begin S:= SimpleQueryservice(SvcName); if S <> serviCE_STOPPED then begin SimpleStopservice(SvcName,True,TruE); end; end; end; procedure AfterserviceInstall(SvcName,Filename: String); begin //If service is not installed,it needs to be installed now if not serviceExists(SvcName) then begin if SimpleCreateservice(SvcName,'My service Name',ExpandConstant('{app}')+'\' + Filename,serviCE_AUTO_START,'',false,TruE) then begin //service successfully installed SimpleStartservice(SvcName,TruE); end else begin //service failed to install end; end; end;
当第一次安装服务(不存在并且当前不运行)时,此服务的安装/启动工作正常.但是,在现有安装(升级)上运行此安装程序时,安装程序在识别到此服务正在运行时停止,并提示终止进程(在调用BeforeserviceInstall()处理程序之前)…
如何防止此提示出现在服务中?我避免不必要重新启动,并且仍然希望这个提示出现在所有其他文件中.
CloseApplications
指令值设置为no),我不推荐这样做.或者您可以为文件设置一个过滤器,这将被检查(在
CloseApplicationsFilter
指令中),您可能需要这样的过滤器.列出除服务可执行文件之外的所有文件,这很难维护.
您也可以列出所有要检查的文件,方法是指定一个不匹配任何文件的过滤器,并从RegisterExtraCloseApplicationsResources
事件方法中添加它们与上述指令相同.
我建议的是从PrepareToInstall
事件方法停止您的服务.它的参考明确地表明了(我强调的):
在执行所有正在使用的文件检查之前执行此事件方法,并且允许您说出因某些原因停止服务失败时需要重新启动系统.如果您不需要重新启动,您可能只是返回一个字符串,并显示了一些明智的消息.
对于您的脚本,这意味着将代码从BeforeserviceInstall过程移动到PrepareToInstall
事件方法,并从条目中删除BeforeInstall参数.
以上是大佬教程为你收集整理的Inno安装 – 在文件复制前正确停止服务全部内容,希望文章能够帮你解决Inno安装 – 在文件复制前正确停止服务所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。