Uninstall service

41 views
Skip to first unread message

Jack Duijf

unread,
Apr 16, 2026, 7:39:41 AM (8 days ago) Apr 16
to innosetup
Hello,

My setupscript installs en starts a service in de Windows Service controller.
All is done in Pascal scripting. Works like a charm.

Now i need the uninstaller to work as follows:

If service is installed and 
    can be stopped and 
    can be uninstalled from the ServiceControler 
     then continue uninstall. (Remove files)
otherwise
     abort the uninstall with a message 
end
How to do this for the uninstaller only.
In other words: Where to put the code below?

var lDone: Boolean;
lDone := false
If IsServiceInstalled('{ServiceId}') then begin 
    If IsServiceStop('{ServiceId}') then begin 
       If ServiceRemove('{ServiceId}') then begin ;
           lDone := true;
       end;
    end; 
End;
Return 

Regards,
Jack Duijf 

Bill Stewart

unread,
Apr 16, 2026, 8:10:01 AM (8 days ago) Apr 16
to innosetup
On Thursday, April 16, 2026 at 5:39:41 AM UTC-6 Jack Duijf wrote:

Now i need the uninstaller to work as follows:

If service is installed and 
    can be stopped and 
    can be uninstalled from the ServiceControler 
     then continue uninstall. (Remove files)
otherwise
     abort the uninstall with a message 
end
How to do this for the uninstaller only.
In other words: Where to put the code below?

var lDone: Boolean;
lDone := false
If IsServiceInstalled('{ServiceId}') then begin 
    If IsServiceStop('{ServiceId}') then begin 
       If ServiceRemove('{ServiceId}') then begin ;
           lDone := true;
       end;
    end; 
End;
Return

The documentation[1] is quite helpful. For example, the "Pascal Scripting: Uninstall Code"[2] topic links to the "Pascal Scripting: Event Functions"[3] topic. Scroll down on that page, and you will see a heading titled "Uninstall event functions". Likely you could use the CurUninstallStepChanged event procedure at the usUninstall stage for your code.

Gavin Lambert

unread,
Apr 16, 2026, 7:01:09 PM (7 days ago) Apr 16
to innosetup
On Friday, April 17, 2026 at 12:10:01 AM UTC+12 Bill Stewart wrote:
The documentation[1] is quite helpful. For example, the "Pascal Scripting: Uninstall Code"[2] topic links to the "Pascal Scripting: Event Functions"[3] topic. Scroll down on that page, and you will see a heading titled "Uninstall event functions". Likely you could use the CurUninstallStepChanged event procedure at the usUninstall stage for your code.

Though note that while this is the proper event to carry out uninstallation tasks, it's too late at that point to abort the uninstall.  You will need to carry on with the rest of the uninstall regardless, though you can still report an error if something fails to uninstall correctly.

If you want to perform a check if something can be uninstalled (without doing the actual uninstall yet) with the option to abort the uninstall, then InitializeUninstall is the place to do that.  For your current example, though, you probably should not use this since your "checks" are actually performing uninstall tasks.

Jack Duijf

unread,
Apr 17, 2026, 4:55:56 AM (7 days ago) Apr 17
to innosetup
Hello,

Thank you for pointing out the help sections.
It took some effords, but i managed it.
My uninstaller now works as expected.

Regards,
Jack Duijf

Op donderdag 16 april 2026 om 14:10:01 UTC+2 schreef Bill Stewart:
Reply all
Reply to author
Forward
0 new messages