加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Inno安装 – 在文件复制前正确停止服务

发布时间:2020-12-15 04:27:16 所属栏目:大数据 来源:网络整理
导读:我们的安装过程包括一个 Windows服务,如果我们的软件被配置为安装为服务器(与客户端安装),则安装该服务.我添加了 a service library能够管理的服务,然后在文件中,我为BeforeInstall和AfterInstall事件添加了处理程序… [Files]Source: "MyService.exe"; Dest
我们的安装过程包括一个 Windows服务,如果我们的软件被配置为安装为服务器(与客户端安装),则安装该服务.我添加了 a service library能够管理的服务,然后在文件中,我为BeforeInstall和AfterInstall事件添加了处理程序…
[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事件方法停止您的服务.它的参考明确地表明了(我强调的):

You can use this event function to detect and install missing
prerequisites and/or to shutdown any application which is about to
be updated
.

在执行所有正在使用的文件检查之前执行此事件方法,并且允许您说出因某些原因停止服务失败时需要重新启动系统.如果您不需要重新启动,您可能只是返回一个字符串,并显示了一些明智的消息.

对于您的脚本,这意味着将代码从BeforeServiceInstall过程移动到PrepareToInstall事件方法,并从条目中删除BeforeInstall参数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读