Inno Setup语法错误2

时间:2016-05-23 17:51:37

标签: inno-setup pascal

我再一次与Pascal语法作斗争。

我只是不应该在开始和结束时使用它。

我目前的方法就是这样,但Inno安装程序告诉我,在行中预计会有分号,如果IsServiceRunning(' oscmaintenanceservice')= true,那么"

有人可以对此有所了解吗?

谢谢!

begin
   if (CurStep=ssInstall) then
           MsgBox('ssInstall.', mbInformation, MB_OK);
           if IsServiceInstalled('oscmaintenanceservice') = true then
               MsgBox('ssInstall: Service is installed.', mbInformation, MB_OK);
               if IsServiceRunning('oscmaintenanceservice') = true then
                           MsgBox('ssInstall: Service is running.', mbInformation, MB_OK);
                       if not StopService('oscmaintenanceservice') = true then
                               MsgBox('ssInstall: Couldnt stop service.', mbInformation, MB_OK);
                       else
                               MsgBox('ssInstall: Service was stopped.', mbInformation, MB_OK);
                           if not RemoveService('oscmaintenanceservice') = true then
                                   MsgBox('ssInstall: Couldnt remove service.', mbInformation, MB_OK);
                           else
                                   MsgBox('ssInstall: Service was removed', mbInformation, MB_OK);
               else
                       MsgBox('ssInstall: Service not running.', mbInformation, MB_OK);
               end;
           else
                   MsgBox('ssInstall: Service not installed.', mbInformation, MB_OK);
   if (CurStep = ssPostInstall) then
       DeleteFile(ExpandConstant('{localappdata}\OnScreenCommunicator\mutex.dat'));
       PinAppTo(ExpandConstant('{app}\OSC.exe'),  pdStartMenu);
       if (IsHigherThanWindowsXP()) then
       begin
           PinAppTo(ExpandConstant('{app}\OSC.exe'), pdTaskbar);
       end;
       if not InstallService(ExpandConstant('{app}\maintenanceservice.exe'),'oscmaintenanceservice','oscmaintenanceservice','desc', SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START) = true then
       begin
           MsgBox('ssPostInstall: Couldnt install service.', mbInformation, MB_OK);
       end;
       if not StartService(ExpandConstant('{app}\maintenanceservice.exe')) then
       begin
           MsgBox('ssPostInstall: Couldnt start service.', mbInformation, MB_OK);
       end

1 个答案:

答案 0 :(得分:1)

这是您的代码版本,其最小编号为beginend;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    MsgBox('ssInstall.', mbInformation, MB_OK);

    if IsServiceInstalled('oscmaintenanceservice') then
    begin
      MsgBox('ssInstall: Service is installed.', mbInformation, MB_OK);

      if IsServiceRunning('oscmaintenanceservice') then
      begin
        MsgBox('ssInstall: Service is running.', mbInformation, MB_OK);

        if not StopService('oscmaintenanceservice') then
          MsgBox('ssInstall: Couldnt stop service.', mbInformation, MB_OK)
        else
          MsgBox('ssInstall: Service was stopped.', mbInformation, MB_OK);

        if not RemoveService('oscmaintenanceservice') then
          MsgBox('ssInstall: Couldnt remove service.', mbInformation, MB_OK)
        else
          MsgBox('ssInstall: Service was removed', mbInformation, MB_OK);
      end
        else MsgBox('ssInstall: Service not running.', mbInformation, MB_OK)
    end
      else MsgBox('ssInstall: Service not installed.', mbInformation, MB_OK)
  end;

  if CurStep = ssPostInstall then
  begin
    DeleteFile(ExpandConstant('{localappdata}\OnScreenCommunicator\mutex.dat'));
    PinAppTo(ExpandConstant('{app}\OSC.exe'),  pdStartMenu);

    if IsHigherThanWindowsXP() then
      PinAppTo(ExpandConstant('{app}\OSC.exe'), pdTaskbar);

    if not InstallService(ExpandConstant('{app}\maintenanceservice.exe'), 'oscmaintenanceservice', 'oscmaintenanceservice', 'desc', SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START) then
    begin
      MsgBox('ssPostInstall: Couldnt install service.', mbInformation, MB_OK);

      if not StartService(ExpandConstant('{app}\maintenanceservice.exe')) then
        MsgBox('ssPostInstall: Couldnt start service.', mbInformation, MB_OK)
    end;
  end;
end;

为了进行比较,以下是代码的等效版本,其中包含所有可选/冗余beginend;。也许它会帮助你理解。

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    MsgBox('ssInstall.', mbInformation, MB_OK);

    if IsServiceInstalled('oscmaintenanceservice') then
    begin
      MsgBox('ssInstall: Service is installed.', mbInformation, MB_OK);

      if IsServiceRunning('oscmaintenanceservice') then
      begin
        MsgBox('ssInstall: Service is running.', mbInformation, MB_OK);

        if not StopService('oscmaintenanceservice') then
        begin
          MsgBox('ssInstall: Couldnt stop service.', mbInformation, MB_OK);
        end
          else
        begin
          MsgBox('ssInstall: Service was stopped.', mbInformation, MB_OK);
        end;

        if not RemoveService('oscmaintenanceservice') then
        begin
          MsgBox('ssInstall: Couldnt remove service.', mbInformation, MB_OK);
        end
          else
        begin
          MsgBox('ssInstall: Service was removed', mbInformation, MB_OK);
        end;
      end
        else
      begin
        MsgBox('ssInstall: Service not running.', mbInformation, MB_OK);
      end;
    end
      else
    begin
      MsgBox('ssInstall: Service not installed.', mbInformation, MB_OK);
    end;
  end;

  if CurStep = ssPostInstall then
  begin
    DeleteFile(ExpandConstant('{localappdata}\OnScreenCommunicator\mutex.dat'));
    PinAppTo(ExpandConstant('{app}\OSC.exe'),  pdStartMenu);

    if IsHigherThanWindowsXP() then
    begin
      PinAppTo(ExpandConstant('{app}\OSC.exe'), pdTaskbar);
    end;

    if not InstallService(ExpandConstant('{app}\maintenanceservice.exe'), 'oscmaintenanceservice', 'oscmaintenanceservice', 'desc', SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START) then
    begin
      MsgBox('ssPostInstall: Couldnt install service.', mbInformation, MB_OK);

      if not StartService(ExpandConstant('{app}\maintenanceservice.exe')) then
      begin
        MsgBox('ssPostInstall: Couldnt start service.', mbInformation, MB_OK);
      end;
    end;
  end;
end;

一旦你理解了这一点,请接受副本,或完全删除你的问题。