Maiken Roskilde
Maiken Roskilde

Reputation: 473

Inno Setup Syntax error in function implementation

I have a larger Inno Setup script.

I think it should work fine, but for some reason it does not. The compiler stops in the line function PrepareToInstall

The compiler tells me:

Syntax error.

Does anybody spot my error? Thank you very much!

I have removed some functions of which I think they don't contribute to the problem

[Code]

function IsServiceRunning(ServiceName: string): boolean;
var
    hSCM: HANDLE;
    hService: HANDLE;
    Status: SERVICE_STATUS;
begin
    hSCM := OpenServiceManager();
    Result := false;
    if hSCM <> 0 then
    begin
        hService := OpenService(hSCM, ServiceName, SERVICE_QUERY_STATUS);
        if hService <> 0 then
        begin
            if QueryServiceStatus(hService, Status) then
            begin
                Result := (Status.dwCurrentState = SERVICE_RUNNING)
            end;
            CloseServiceHandle(hService)
        end;
        CloseServiceHandle(hSCM)
    end
end;

function PrepareToInstall(var NeedsRestart: Boolean): String;
   begin
       if IsServiceRunning("oscmaintenanceserver") then begin
           if StopService("oscmaintenanceserver") then begin
               RemoveService("oscmaintenanceserver");
           end;
       end;
   end;
end;

Upvotes: 2

Views: 1105

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202594

It's the "oscmaintenanceserver". There are no double-quotes in Pascal (Script). You always use single-quotes for string literals.

Moreover, you have one end too much in the PrepareToInstall.

The correct code is:

function PrepareToInstall(var NeedsRestart: Boolean): String;
   begin
       if IsServiceRunning('oscmaintenanceserver') then begin
           if StopService('oscmaintenanceserver') then begin
               RemoveService('oscmaintenanceserver');
           end;
       end;
   end;

Upvotes: 2

Related Questions